1

I am receiving from the server the following response:

Object {
  $type: "base64",
  $data: "JVBERi0xLjQK..."
}

I try to autodownload it with FileSaver.js

    let arrayBuffer = atob(response.$data);
    let blob = new Blob([arrayBuffer], {type: "application/pdf;charset=utf-8"});
    saveAs(blob, 'myfile.pdf');

A PDF is generated, and downloads (it has the same page number as the original on the server), but is empty. However this works:

window.open("data:application/pdf;base64," + response.$data);

It opens the PDF with its content.

user3568719
  • 1,036
  • 15
  • 33
  • Possible duplicate of [Creating a Blob from a base64 string in JavaScript](https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript) – Endless Oct 19 '17 at 19:32
  • You are not creating the blob correctly, pls read "creating a blob from base64" – Endless Oct 19 '17 at 19:33
  • For people who are looking for a solution, it is answered here: https://stackoverflow.com/a/45669785/807101 – Sterex Jan 29 '19 at 13:05

0 Answers0