Some test text!

Loading...
Guides
Why does my office file only have 1 page in documentLoaded?

Why does my office file only have 1 page in documentLoaded?

When loading office files, each page is loaded in sequence.

So when the following code is run, the result is that the office file only has 1 page:

documentViewer.addEventListener('documentLoaded', () => {
  documentViewer.getCompleteRotation(2); // Throws exception as page 2 is not loaded yet
  console.log(documentViewer.getPageCount()); // Returns 1
});

To get the document with all pages loaded, you can await the documentCompletePromise. This promise will resolve when all of the page information is available for the document.

documentViewer.addEventListener('documentLoaded', async () => {
  await documentViewer.getDocument().documentCompletePromise();
  documentViewer.getCompleteRotation(2); // Works now as all pages are loaded
  console.log(documentViewer.getPageCount()); // Returns the correct page count
});

Get the answers you need: Support

Upcoming Webinar: PDFTron SDK Tech Review | Nov 29, 2022 at 2 pm ET

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use