I'm writing a program that uses a generic template that was converted from PDF to HTML to create personalized reports for individuals. In order to convert the final HTML files back to PDF I am using PyQT5 and its printToPdf method. It works perfectly once, but the program hangs until I close the widget view that opens, at which point it segfaults and ends the entire python program. How can I close the program peacefully programmatically so that I can render all of the HTML in one sweep? Perhaps there is some way not to forfeit the thread over to the widget?
Here is my current code.
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()