Is it possible to get the document total page count from a WebViewer instance?

PDF.js Express Version
7.3.2

Detailed description of issue
Hi guys, I am launching a WebViewer instance, and wonder if it contains the total number of pages of the document the instance loads.

Expected behaviour
I found a getPageCount() method but on the “DocumentViewer” class… wondering if there is something similar I could call when I create an instance of the Web viewer:

WebViewer(
    {
        etc
    },
    viewer.current,
).then((instance) => {
     --> I need to get the loaded doc's total page count in here

Does your issue happen with every document, or just one?
Any document.

Link to document
Not applicable.

Code snippet
WebViewer(
{
etc
},
viewer.current,
).then((instance) => {
→ I need to get the loaded doc’s total page count in here

Thanks!

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi Carlos,

To get the page count you first need to wait for the document to load. You can do that by using the docViewer event documentLoaded. Here is a code snippet to get the page count.

 document.getElementById('viewer')).then(instance => {
  const {docViewer} = instance;
  docViewer.on('documentLoaded', () => {
    const pageCount = docViewer.getPageCount();
    console.log(pageCount);
  });
});

Cheers,
Dustin

1 Like