|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 haiyingbs 于 2022-8-30 17:14 编辑
要关闭窗口(退出程序)才可以生成PDF,怎么才可以不关闭窗口就可以生成PDF
代码如下:
import sys, os
from datetime import date, timedelta
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import QMarginsF
from PyQt5.QtPrintSupport import QPrinter
from PyQt5.QtGui import QPageLayout, QPageSize
app = QtWidgets.QApplication(sys.argv)
loader = QtWebEngineWidgets.QWebEngineView()
loader.load(QtCore.QUrl('https://fishc.com.cn/forum-173-1.html'))
layout = QPageLayout(
QPageSize(QPageSize.B5),
QPageLayout.Portrait, QMarginsF(0, 0, 0, 0)
)
def printFinished():
page = loader.page()
print("%s Printing Finished!" % page.title())
def printToPDF(finished):
loader.show()
page = loader.page()
page.printToPdf("%s.pdf" % page.title(), layout)
loader.page().pdfPrintingFinished.connect(printFinished)
loader.loadFinished.connect(printToPDF)
app.exec_() |
|