May 2019
Intermediate to advanced
542 pages
13h 37m
English
In this paperless digital age, the PDF file has replaced the hard copy for many purposes, so an easy export to PDF function is always a good thing to add. QPrinter can do this for us easily.
Add the following export_pdf() method to MainView:
def export_pdf(self): filename, _ = qtw.QFileDialog.getSaveFileName( self, "Save to PDF", qtc.QDir.homePath(), "PDF Files (*.pdf)") if filename: self.printer.setOutputFileName(filename) self.printer.setOutputFormat(qtps.QPrinter.PdfFormat) self._print_document()
Here, we're going to start by asking the user for a filename. If they provide one, we'll configure our QPrinter object with the filename, set the output format to PdfFormat, and then print the document. When writing to a file, ...
Read now
Unlock full access