是否可以让 QWebKit 显示 pdf 文件? [英] Is it possible to get QWebKit to display pdf files?
问题描述
我的 QWebkit 中有一个链接,指向一个 pdf 文件.但是当点击链接时,它无法显示pdf文件.有没有办法让它发生?
i have a link in my QWebkit, which points to a pdf file. But when the link is clicked, it can't display the pdf file. is there a way to make it happen?
推荐答案
如果您通过 QWebSettings 启用插件并安装了提供浏览器插件(例如 Acrobat)的 PDF 查看器,那么您应该会在 QWebView 中看到使用该插件呈现的 PDF:
If you enable plugins through QWebSettings and have a PDF viewer installed that provides a browser plugin such as Acrobat then you should see the PDF rendered using the plugin inside your QWebView:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
app = QApplication(sys.argv)
web = QWebView()
web.settings().setAttribute(QWebSettings.PluginsEnabled, True)
web.show()
web.load(QUrl('file:///C:/test/test.pdf')) # Change path to actual file.
sys.exit(app.exec_())
此代码在装有最新版 Acrobat X 的 Windows 上对我不起作用(它只显示进度条,但没有显示 PDF - 证明插件正在加载,只是不工作)但我确定这是怎么回事我以前做过.试试看,让我知道.
This code isn't working for me on Windows with the latest version of Acrobat X (it just shows a progress bar but no PDF - proof that the plugin is loading, just not working) but I'm sure this is how I've done it before. Give it a try and let me know.
这篇关于是否可以让 QWebKit 显示 pdf 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!