用qwebengineview在PDF.JS中进行编程更改页面
我正在PYQT5中制作一个应用程序,该应用程序涉及使用qwebengineview
和pdf.js
by Mozilla显示PDF。
我能够显示PDF没问题,但是我无法弄清楚如何:
- 1:将页面设置为“加载”页面,或
- 2:在已经加载后更新页面,
我尝试了其他涉及的stackoverflow帖子中的许多选项使用self.runjavascript()
将其更改,但它始终导致“无法设置未定义的属性”或“对象是非电视”。
这是我的方法:
def load_file(self, file, page=0) -> None:
url = QtCore.QUrl().fromLocalFile(os.path.abspath("./pdfjs/web/viewer.html"))
query = QtCore.QUrlQuery()
query.addQueryItem("file", os.path.normpath(os.path.abspath(file)))
url.setQuery(query)
self.pdf_view.load(url)
其中self.pdf_view
是qwebengineview。
我将感谢有关如何实现这一目标的任何帮助。
编辑:我能够使用#
符号在加载上指定页面,但是关于更改页面而不重载整个内容,我仍然未知。
I am making an application in PyQt5 that involves displaying a PDF using the QWebEngineView
and PDF.js
by Mozilla.
I am able to display the PDF no problem, but I cannot figure out how to either:
- 1: set the page on load, or
- 2: update the page after it is already loaded
I have tried the numerous options from other Stackoverflow posts that involve using self.runJavaScript()
to change it, but it always results in either "Cannot set property of undefined" or "Object is NoneType".
Here is my method:
def load_file(self, file, page=0) -> None:
url = QtCore.QUrl().fromLocalFile(os.path.abspath("./pdfjs/web/viewer.html"))
query = QtCore.QUrlQuery()
query.addQueryItem("file", os.path.normpath(os.path.abspath(file)))
url.setQuery(query)
self.pdf_view.load(url)
where self.pdf_view
is QWebEngineView.
I would appreciate any help on how to accomplish this.
EDIT: I was able to specify the page on load with the #
symbol, but as for changing the page without re-loading the whole thing is still unknown to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pdf.js
查看器加载一些创建pdfviewer
对象具有所有必要属性的脚本,以编程性地导航页面。因此,您只需要在主查看器页面上运行一些简单的JavaScript即可获得所需的功能。为了使事情变得更好一些,也有助于提供一种同步运行JavaScript的方法,以便更轻松地访问返回值。以下是一个简单的工作演示,它实现了该演示(仅在Linux上测试)。希望应该很清楚如何适应您自己的应用程序:
The
PDF.js
viewer loads some scripts that create aPDFViewer
object with all the necessary properties for programmatically navigating pages. So you just need to run some simple javascript on the main viewer page to get the functionality you need. To make things a little nicer to work with, it's also helpful to provide a way to run the javascript synchronously so that return values can be accessed more easily.Below is a simple working demo that implements that (only tested on Linux). Hopefully it should be clear how to adapt it to work with your own application: