How can I get the current PDF page number from PDF

2019-05-19 05:15发布

问题:

I have the viewer hosted on my local webserver and the iframe points and loads up the pdf.

I then want to press a button that 'logs' the page number to a text file, I read this question and answer which seems to suggest you can use pdf.getPage to get the page number but how can i access the PDFJS when it is being ran from inside of the iframe?

Thank you.

回答1:

var iFrame =  document.getElementById('iframe_id');
if ( iFrame.contentDocument ) {
    currentPageNum= iFrame.contentDocument.getElementById('pageNumber').value;
}
alert(currentPageNum);

This will access the iframe and then search the viewer.html for the element that contains the page number. All that needs doing now is to pass currentPageNum to the form.



标签: iframe pdf.js