0

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?

  • Have you tried converting the base64 stream into a string ? (Why it’s longer is because it’s in base64) – Stephen Aug 06 '18 at 07:28
  • check [this answer](https://stackoverflow.com/questions/50156827/read-pdf-as-arraybuffer-to-store-it-in-json-file-with-detailed-information) – Margon Aug 06 '18 at 07:36

0 Answers0