Get Current Page number of Embedded pdf

2019-01-28 08:54发布

问题:

I am planning to develop a webapp. The page will have an iframe on the left side and javascript form on right side. The iframe will be used to view pdfs from server.

I have been looking for ways to capture or get the current page number of the pdf being viewed in the iframe.

Is this possible?

回答1:

One suggestion would be to try and use PDF.js, a PDF viewer that is built with HTML5. This might help you get around the need to use an iFrame to render the PDFs. But, if you need the iFrame for other reasons, then try looking at the PDF.js examples. As indicated on a previous stackoverflow thread, there are functions you could take advantage of:

PDFJS.getDocument('helloworld.pdf').then(function(pdf) {
    // you can now use *pdf* here

    pdf.getPage(1).then(function(page) {
            // you can now use *page* here
        });
}); 

Hope this helps the cause.