Q: How do I set the initial page that should be opened when a PDF
document is opened?
----
A: You can use prefs.SetInitialPage(dest) in the PDFViewPrefs class.
For example,
....
PDFDocViewPrefs prefs = pdfdoc.GetViewPrefs();
Destination dest_page = Destination.CreateFit(page);
// = Destination.CreateFit(pdfdoc.GetPage(page_num));
prefs.SetInitialPage(dest_page);
1 Like
How can achieve this in WebViewer, how can I load a specific page (e.g., page 55) first instead of page one? The PDF is linearized, and I want to optimize loading by prioritizing the target page.
an example in React would be great
1 Like
Hi Jauhar,
The best way to set up the page would be to wait for the document to be ready, get the total page count to be sure your desired page index exists, and then use the property setCurrentPage.
documentViewer.addEventListener('documentLoaded', () => {
const totalPage = documentViewer.getPageCount()
const defaultPageNum = 3
if (defaultPageNum <= totalPage) {
documentViewer.setCurrentPage(defaultPageNum)
}
});
Best Regards,
Mickaël.
2 Likes
Hi Mickaël,
Thank you for the quick and clear example! 
Is there a way to leverage the PDF’s linearization to ensure the desired page loads first (before other pages) when using setCurrentPage? For instance, can WebViewer prioritize fetching the data for a specific page immediately, then load adjacent pages afterward?
I am looking for something like providing the initialPage to the WebViewer function itself.
This would avoid downloading/render-blocking on initial pages entirely, which is critical for large documents. If this isn’t supported today, is it something planned for the near future? or achievable using some custom logic
Your insights would help us finalize our decision. Thanks again!
1 Like
Hi Jauhar,
This solution is already preventing render-blocking.
Here are the lifecycle events of the WebViewer. As you can see here, when the event “document loaded” is emitted, the file is loaded into memory but is not rendered yet.
I went to JS Large Files Viewer Demo | Apryse WebViewer and loaded the 2GB file after setting the code I gave you, except I set the defaultPageNum to 100, I was instantly brought to page 100, and in the network tab, I can see the document is loading the rest of the document.
I recorded my screen so you can see if this is what you had in mind: OneDrive
Let me know if that’s working for you.
Best Regards,
Mickaël.
2 Likes