我正在写一个程序,它使用一个通用的模板,从PDF转换成HTML,为个人创建个性化的报告。为了将最终的HTML文件转换回PDF,我使用PyQT5及其printToPdf方法。它可以完美地工作一次,但程序会一直挂起,直到我关闭打开的widget视图,此时它会分段并结束整个python程序。如何以编程方式和平地关闭程序,以便在一次扫描中呈现所有HTML?也许有什么办法不放弃线程到小部件?你知道吗
这是我现在的密码。你知道吗
for htmlFileAsString in files:
app = QtWidgets.QApplication(sys.argv)
loader = QtWebEngineWidgets.QWebEngineView()
loader.setZoomFactor(1)
loader.setHtml(htmlFileAsString)
loader.page().pdfPrintingFinished.connect(
lambda *args: print('finished:', args))
def emit_pdf(finished):
loader.show()
loader.page().printToPdf('output/' + name + '/1.pdf')
loader.loadFinished.connect(emit_pdf)
app.exec()
如the ekhumoro answer中所述,问题是您无法创建多个QApplication(您必须查看所示的答案以了解更多详细信息),因此应用相同的技术,解决方案如下:
相关问题 更多 >
编程相关推荐