使用 PyQt 转换网页到 PDF(使用QtWebKit加载完毕后,打印整个窗口就行了,真简单!)

import sys

try:
from PyQt4 import QtWebKit
from PyQt4.QtCore import QUrl
from PyQt4.QtGui import QApplication, QPrinter
except ImportError:
from PySide import QtWebKit
from PySide.QtCore import QUrl
from PySide.QtGui import QApplication, QPrinter app = QApplication(sys.argv) def done(status):
p = QPrinter()
p.setOutputFormat(QPrinter.PdfFormat)
p.setOutputFileName('a.pdf')
view.print(p)
app.exit() view = QtWebKit.QWebView()
view.load(QUrl('http://lilydjwg.is-programmer.com/'))
view.loadFinished[bool].connect(done)
# PySide does not have QApplication.exec
app.exec_()

http://www.seanyxie.com/%E4%BD%BF%E7%94%A8-pyqt-%E8%BD%AC%E6%8D%A2%E7%BD%91%E9%A1%B5%E5%88%B0-pdf/

上一篇:poj 3522(最小生成树应用)


下一篇:解读Unity中的CG编写Shader系列三