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

3

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.