Hi everyone :)
Wonder if there is a way to remove page number on QTextDocument's print(QPrinter*)
Printable View
Hi everyone :)
Wonder if there is a way to remove page number on QTextDocument's print(QPrinter*)
Finally I get my solution,
Instead of QTextDocument's print(), I use QTextDocument's drawContents().
Codes below will show the way how to do this:
Code:
QTextDocument textDocument; QSizeF paperSize; paperSize.setWidth(printer->width()); paperSize.setHeight(printer->height()); textDocument.setPageSize(paperSize); textDocument.setHtml(contentFormula); //contentFormula contains some html tags textDocument.drawContents(&painter);
:) hope this'll be usefull
Hello,
you can also use the print() method to print without the page number!
The key is, that the QTextDocument needs a valid pageSize.
Code:
printer.setOutputFileName( fileName ); // printer.setPageMargins(0.925, 0.8, 0.5, 0.8, QPrinter::Inch); QSizeF paperSize; paperSize.setWidth(printer.width()); paperSize.setHeight(printer.height()); document->setHtml(html); document->setPageSize(paperSize); // the document needs a valid PageSize document->print(&printer);
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 will be just printed, if pageNumberPos is not null.
So just set a valid QTextDocumtent.pageSize() and you have no page numbers on your printed document.
I hope this bug will be fixed in a future release. (It's a reported bug)
good luck