Brent Moses
Brent Moses

Reputation: 253

How to store PDF.js document in local storage? How To use viewer.js with raw pdf source?

I have 2 questions revolving around displaying pdfs in a browser.

When I try to store a PDF.js document in local storage it does not work and crashes the javascript. Code below.

PDFJS.getDocument(array).then(function getPdfHelloWorld(_pdfDoc) {
    localStorage.setItem("pageNum", pageNum);
    localStorage.setItem("pdf-obj", JSON.stringify(_pdfDoc));
    pdfDoc = _pdfDoc;
    renderPage(pageNum);
  });

Any ideas?

Also since I may not be able to use paging this way I may need to look into using viewer.js for display and paging. I am wondering if there is a way to use viewer.js with raw pdf source rather than a file because that is all I have available to me. Thanks for any help.

Upvotes: 2

Views: 4265

Answers (1)

Vincent Scheib
Vincent Scheib

Reputation: 18610

How to store PDF.js document in local storage?

PDFJS.getDocument returns a PDFDocumentProxy object which is quite likely not JSON serializable. (Check developer console output to this effect, it would help if your question stated HOW the javascript code is crashing). It is lik

How To use viewer.js with raw pdf source?

An ArrayBuffer can be passed to getDocument. See Pdf.js: rendering a pdf file using a base64 file source instead of url.

Upvotes: 3

Related Questions