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:

JavaScript

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

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.

JavaScript

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

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales