I have base64 stream of a pdf file. Now I need to convert it into a pdf file in Native Javascript.
let x=atob(base64);
saveByteArray(x.split(""),"result.pdf");
var saveByteArray = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, name) {
var blob = new Blob(data, {type: "application/pdf"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
};
}());
Its converting to pdf and the pdf file is opened but its not correctly formatted or decoded so its blank. when i try to convert it using some online resources its opened correctly and displaying the output. more over the file size is 1.43MB from online and from code it is 2MB. I don't what happened. May be due to format.
Sample base64 stream --> JVBERi0xLjMKJeLjz9MKMSAwIG9iago8PC9GaWx0ZXIvRmxhdG.... How can I solve this issue?