Some test text!

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: SDK Features Preview and Live Run-Through | July 14, 2022 at 11 am PT


The Platform


© 2022 PDFTron Systems Inc. All rights reserved.


Terms of Use