downloadDocument("pkb-agreement-person")
.then((str) => {
let encode = encodeURIComponent(
str
).replace(/%([a-f0-9]{2})/gi, (m, $1) =>
String.fromCharCode(parseInt($1, 16))
);
return btoa(encode);
})
.then((data) => {
let content = data;
let contentType =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document";
let sliceSize = 512;
let byteCharacters = window.atob(content);
let byteArrays = [];
for (
let offset = 0;
offset < byteCharacters.length;
offset += sliceSize
) {
let slice = byteCharacters.slice(
offset,
offset + sliceSize
);
let byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
let byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
let blob = new Blob(byteArrays, {
type: contentType,
});
let blobURL = URL.createObjectURL(blob);
window.open(blobURL);
});