Some test text!

Search
Hamburger Icon

Web / FAQ / 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
});

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales