代码很简单,功能也很简单 =w=
webpage2pdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/env python3 import sys try : 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_() |
注意:虽然没有图形界面,但是还是需要 X 连接……