Jump to page in PDF.js with javascript

前端 未结 3 1109
悲&欢浪女
悲&欢浪女 2021-02-04 21:00

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

3条回答
  •  情深已故
    2021-02-04 21:03

    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;
    }
    

提交回复
热议问题