Jump to page in PDF.js with javascript

前端 未结 3 1103
悲&欢浪女
悲&欢浪女 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;
    }
    
    0 讨论(0)
  • 2021-02-04 21:18

    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
    
    0 讨论(0)
  • 2021-02-04 21:24

    In my case I was loading pdf file inside iframe so I had to do it in other way around.

    function goToPage(desiredPage){
    var frame_1 = window.frames["iframe-name"];
    var frameObject = document.getElementById("iframe-id").contentWindow;
    frameObject.PDFViewerApplication.page = desired page;
    }
    
    0 讨论(0)
提交回复
热议问题