This has been answered elsewhere, but for those who arrive here seeking the solution, I'm reposting it: you need to set a pageSize in the document, like so:
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
document.setHtml("<p>Lorem ipsum</p>");
document.setPageSize(printer.pageRect().size()); // <-- Here is key to the solution
document.print(&printer);
QPrinter printer(QPrinter::PrinterResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(fileName);
QTextDocument document;
document.setHtml("<p>Lorem ipsum</p>");
document.setPageSize(printer.pageRect().size()); // <-- Here is key to the solution
document.print(&printer);
To copy to clipboard, switch view to plain text mode
The explanation is simple, albeit not entirely intuitive. Paraphrasing @shoyeb from that thread:
When you refer the source code of print(), then you will recognize that the
< QPointF pageNumberPos; > is only defined when there is no valid
QTextDocument.pageSize().
In
printPage() the page number only will be printed if
pageNumberPos is not null.
So just set a valid
QTextDocumtent.pageSize() and you'll have no page numbers on your printed document.
Bookmarks