Jump to page in PDF.js with javascript

放肆的年华 提交于 2020-01-01 00:43:09

问题


I'm trying to use PDF.js' viewer to display pdf files on a page.

I've gotten everything working, but I would like to be able to 'jump to' a specific page in the pdf. I know you can set the page with the url, but I would like to do this in javascript if it's possible.

I have noticed that there is a PDFJS object in the global scope, and it seems that I should be able to get access to things like page setting there, but it's a rather massive object. Anyone know how to do this?


回答1:


You can set the page via JavaScript with:

var desiredPage = [the page you want];
PDFViewerApplication.page = desiredPage;

There is an event handler on this, and the UI will be adjusted accordingly. You may want to ensure this is not out of bounds:

function goToPage(desiredPage){
    var numPages = PDFViewerApplication.pagesCount;
    if((desiredPage > numPages) || (desiredPage < 1)){
        return;
    }
    PDFViewerApplication.page = desiredPage;
}



回答2:


if Pdf shown into iframe and you want to navigate to page then use below code. 'docIfram' is iframe tag Id.

document.getElementById("docIframe").contentWindow.PDFViewerApplication.page=2


来源:https://stackoverflow.com/questions/29807055/jump-to-page-in-pdf-js-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!