I can't print my pdf file using QPrinter, I figured it needs to be set to html to print it and now I'm getting this error on terminal:
QPrintDialog: Cannot be used on non-native printers.
And does setting it to html like this change what my pdf file look like?.
def print_pdf(self, pdffile):
printer = QPrinter()
printer.setOutputFileName(pdffile)
printer.setPageSize(QPageSize(QPageSize.PageSizeId.A6))
# Create a QTextDocument to hold the contents of the PDF file
document = QTextDocument()
document.setHtml("<html><body><img src='file://" + pdffile + "'/></body></html>") # Load PDF content
# a print dialog
print_dialog = QPrintDialog(printer, self)
if print_dialog.exec() == QPrintDialog.DialogCode.Accepted:
# Print the document
document.print(printer)
<img>tag; 3. you're trying to print on a pdf file that you're also attempting to display inside the very document you're printing, which makes absolutely no sense at all. It's also unclear what you actually want to do: do you already have a PDF file that you want to print on a physical printer?setOutputFileName(), since you obviously do not need to print to an output file.QPdfDocumentsolution (which wasn't available a that time) described by musicamente in his comment.