Pdf.js: How to render single page using pdf.js

Created on 12 Jun 2015  路  5Comments  路  Source: mozilla/pdf.js

When I load complete document in mobile safari,its running out of memory and the browser crashes,
So, I want to render single page at one time with having all features.
Is it possible to render single page and if how ?

Most helpful comment

hello~ would you mind share how you render just one page by modifying viewer.js? Thanks!

All 5 comments

You have to modify standard viewer to limit display to one page (e.g. fake number of pages in the api).

Mobile safari has defect in range request handling, so we disable fetching only portion of the document on this browser.

Closing as answered.

Thank you!! I have rendered single page by modifying viewer.js and i am unable to search the words. Find Control searches for the first word and it unable to scroll to next word. For loading a single page , i loaded all the pages and made the viewer division as null. Please help me this is critical issue for us.

hello~ would you mind share how you render just one page by modifying viewer.js? Thanks!

@yurydelendik How did you modify the limit display of page ?
Is there any specific property ?

@eghazal1 @chunyenHuang if you're curious, I was able to modify the number of pages displayed by doing something like:

const MAX_PAGES = 3;

PDFJS.getDocument(params).then((doc) => {
    Object.defineProperty(doc, 'numPages', { value: Math.min(doc.numPages, MAX_PAGES) });
    this.pdfViewer.setDocument(doc);
    // Other stuff
}

You may run into issues with the find controller as described above and other edge cases that I haven't tested yet. I used defineProperty since document.numPages doesn't have a setter. You could also modify the pdf_viewer.js code to add a setter for numPages to avoid that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smit-modi picture smit-modi  路  3Comments

BrennanDuffey picture BrennanDuffey  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

AlexP3 picture AlexP3  路  3Comments

SehyunPark picture SehyunPark  路  3Comments