Python PyQt QWebView转PDF - 图像未加载

时间:2017-01-06 05:29:55

标签: python html pdf pyqt

我目前有HTML字符串格式的图像,如下所示:

iVBORw0KGgoAAAANSUhEUgAAAT0AAAGQCAIAAABTeyD6AAAAA3NCSVQICAjb4U/......(cut here).....QZBnijNOpmMG2HY2FPO3I11PkGNcMmV

我正在尝试使用QWebView和QPrinter创建PDF

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebView
import os

FN = os.path.join("Image.pdf")
HTML_FILE = file containing html string

app = QApplication(sys.argv)
view = QWebView()
view.setAttribute(Qt.WA_TranslucentBackground)
view.setAttribute(Qt.WA_OpaquePaintEvent, False)
page = view.page()
palette = page.palette()
palette.setBrush(QPalette.Base, Qt.transparent)
page.setPalette(palette)
page.currentFrame().documentElement().setInnerXml("text")
view.setHtml(HTML_FILE)
printer = QPrinter()
printer.setOutputFileName(FN)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setPageSize(QPrinter.A4)
printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)
view.print_(printer)

当我作为HTML文件编写时,它工作正常并且显示图像但是当我使用QWebKit将其导出为PDF时,图像不会显示。我不擅长HTML,但我一直在尝试所有组合来完成这项工作,但未成功。任何帮助将不胜感激。谢谢!

0 个答案:

没有答案