使用javascript跳转到PDF.js中的页面 [英] Jump to page in PDF.js with javascript
问题描述
我正在尝试使用PDF.js'查看器在页面上显示pdf文件。
I'm trying to use PDF.js' viewer to display pdf files on a page.
我已经完成了所有工作,但我想成为能够跳转到pdf中的特定页面。我知道您可以使用网址设置页面,但如果可能的话,我想在javascript中执行此操作。
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.
我注意到有一个PDFJS对象在全局范围,似乎我应该能够访问那里的页面设置,但它是一个相当大的对象。有人知道怎么做吗?
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?
推荐答案
您可以通过JavaScript设置页面:
You can set the page via JavaScript with:
var desiredPage = [the page you want];
PDFViewerApplication.page = desiredPage;
此处有一个事件处理程序,UI将相应调整。您可能希望确保这不会超出范围:
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;
}
这篇关于使用javascript跳转到PDF.js中的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!