5

Im trying to download a PDF file from binary string, which I receive as a response from an Ajax.

I receive the following data (binaryString):

%PDF-1.4....
.....
....content of file
....
%% EOF

I tried this:

    var blob=new Blob([binaryString], {type: "application/pdf"});// change resultByte to bytes
    var link=document.createElement('a');
    link.href=window.URL.createObjectURL(blob);
    link.download="myFileName.pdf";
    link.click();

And also tried using the download.js library:

download(binaryString, "file.pdf", "application/pdf");

However, both return a PDF with the correct number of pages, but completely blank. enter image description here

Result of API test with insomnia: enter image description here

Dr.G
  • 448
  • 6
  • 19
  • Does this answer your question? [How to build PDF file from binary string returned from a web-service using javascript](https://stackoverflow.com/questions/12876000/how-to-build-pdf-file-from-binary-string-returned-from-a-web-service-using-javas) – Cybernetic Feb 21 '20 at 13:32
  • no, i had already seen it, i based it even, but it doesn't answer – Dr.G Feb 21 '20 at 13:35
  • Can you provide a link to the actual binary string? – Cybernetic Feb 24 '20 at 16:16

1 Answers1

1

The binary string arrives at the corrupted front, so I decided to convert it to base64 on the back end and send it like this, but that's because I have autonomy from the back end, I don't know how it would be resolved for a non-public api and other cases.

Dr.G
  • 448
  • 6
  • 19