5

使用 PyQt 转换网页到 PDF

 2 years ago
source link: https://blog.lilydjwg.me/2014/3/6/convert-web-pages-to-pdf-with-pyqt.43313.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

使用 PyQt 转换网页到 PDF

本文来自依云's Blog,转载请注明。

代码很简单,功能也很简单 =w=

webpage2pdf
#!/usr/bin/env python3
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.loadFinished[bool].connect(done)
# PySide does not have QApplication.exec
app.exec_()

注意:虽然没有图形界面,但是还是需要 X 连接……

发送到 Kindle

Category: python | Tags: Python PyQt Qt | Read Count: 8456

评论 (5)
None 说:
7 年前

自从推特强制 t.co 我就用上了这个:

import sys
from PyQt4 import QtGui
app = QtGui.QApplication(sys.argv)
app.clipboard().setText(u'\u200b')

依云 说:
7 年前

哈,这种特殊字符我会用 fcitx-unicode 依次按 C-S-A-u zero w M-1。当然如果常用的话我会定义成快速输入的 =w=

话说,你为什么不用 printf '\u200b' | xsel 呢?

None 说:
7 年前

啊.. 其实我在用 Windows..

依云 说:
7 年前

原来如此……据说 Windows 上可以用 Alt+小键盘数字键的,不过小键盘我已经很久没见过了……

None 说:
7 年前

我也没有小键盘.. (捂脸
连那种按 Fn 启用的都没有..

不过倒是可以试一下输入法的自定义词典

[取消回复评论]

昵称 登录 E-mail: *
Web:
Twitter:
当有新评论通过 E-mail 通知我

loading captcha image...
(输入验证码)

or Ctrl+Enter


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK