0

Is it possible to save binary content of pdf into javascript variable? I have a webpage with url to saving pdf file and I need to save pdf file into javascript variable. I guess it should be binary data.

1
  • Please read How to Ask. Key phrases: "Search, and research" and "Explain ... any difficulties that have prevented you from solving it yourself". In the future, please try and do the task yourself before asking here. Commented Apr 14, 2017 at 15:26

1 Answer 1

1

You can use XHR with response type blob:

var oReq = new XMLHttpRequest();
oReq.open("GET", "/myfile.pdf", true);
oReq.responseType = "blob";

oReq.onload = function(oEvent) {
  var blob = oReq.response;
  // `blob` contains the PDF content
};

oReq.send();

Source: Sending and Receiving Binary Data, MDN

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.