在 ActiveX 小部件中加载 PDF [英] Load a PDF in a ActiveX widget
问题描述
我正在尝试将 PDF 加载到 QAxWidget
:
I am trying to load a PDF into a QAxWidget
:
self.axWidget = QAxContainer.QAxWidget()
self.axWidget.setProperty("geometry", QtCore.QRect(630, 20, 501, 651))
self.axWidget.setControl("Adobe PDF Reader")
self.axWidget.dynamicCall("LoadFile(const QString)", "test.pdf")
然而,它只加载一个空的灰色背景:
However, it only loads an empty gray background:
我一直在寻找替代方案、外部库、python pdf-to-png 库,然后只是简单地加载图像等.但到目前为止,我发现的每一个结果似乎都对这项任务来说太过分了.
I've been searching for alternatives, external libraries, python pdf-to-png libraries and then just simply load an image, etc. But every result I found so far seems overkill for this task.
因此,由于 Qt 实际上支持 ActiveX 控件,我可以在哪里查看工作示例或 Python 中的 dynamicCalls 的特定文档,以便在 QAxWidget?
So, since Qt actually supports ActiveX controls, where can I check a working example, or the specific documentation for dynamicCalls from Python in order to load the PDF inside a QAxWidget?
我只需要它作为只读数据,所以即使是它的图像也能工作.
I only need it as read-only data, so even an Image of it would work.
推荐答案
我遇到了同样的情况,我无法简单地"在我的应用程序窗口中显示 pdf 文件.
I was in the same situation and I was not able to "simply" show a pdf file in my application windows.
经过大量测试和尝试后,我找到了一种适合我的解决方法.
After a lot of tests and attempts I have found a workaround that works for me.
我没有加载使用 Adobe Acrobat PDF API (AcroPDF64.dll) 的控件 "Adobe PDF Reader"
,而是加载了控件 "Microsoft Web Browser"
使用 Internet Explorer 的 dll(ieframe.dll).
Instead of load the control "Adobe PDF Reader"
, that use Adobe Acrobat PDF API (AcroPDF64.dll), I load the control "Microsoft Web Browser"
that use the dll of Internet explorer (ieframe.dll).
这里是我使用的代码:
pdf = QAxWidget("Microsoft Web Browser")
pdf.dynamicCall("Navigate(const QString&)", pdf_path)
self.Ui.verticalLayout.addWidget(pdf)
首先,我使用 Qt Designer 在我的 Ui
中创建了一个 verticalLayout
容器.
First I create with Qt Designer a verticalLayout
container in my Ui
.
然后我创建一个 QAxWidget
实例,在其中加载控件 "Microsoft Web Browser"
.
Then I create a QAxWidget
instance in which I load the control "Microsoft Web Browser"
.
在pdf_path
变量中保存我的pdf 文件的完整路径后,我Navigate
在我的pdf 完整路径的Web 浏览器中.
After saving in pdf_path
variable, full path of my pdf file, I Navigate
in the Web Browser at my pdf full path.
最后我将 QAxWidget
添加到 verticalLayout
中.
At the end I add the QAxWidget
into verticalLayout
.
通过这种方式,pdf 文件使用 Microsoft Web 浏览器默认插件可视化,在我的例子中是 Acrobat Reader DC.
In this way the pdf file it is visualized with Microsoft Web Browser default plugin, that is Acrobat Reader DC in my case.
刷新或初始化QAxWidget
,即更改pdf文件或自动刷新内容我使用此解决方案:
To refresh or initialize the QAxWidget
, i.e. for change pdf file or automatic refresh the content I use this solution:
for i in reversed(range(self.Ui.verticalLayout.count())):
self.Ui.verticalLayout.itemAt(i).widget().dynamicCall("Navigate(const QString&)", "")
self.Ui.verticalLayout.itemAt(i).widget().deleteLater()
self.Ui.verticalLayout.itemAt(i).widget().destroy(True)
这个for
循环清空了我的Ui.verticalLayout
.
这篇关于在 ActiveX 小部件中加载 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!