PDA

View Full Version : [Help] Remove page number, on QTextDocument's print()



rivci
17th January 2011, 07:27
Hi everyone :)

Wonder if there is a way to remove page number on QTextDocument's print(QPrinter*)

rivci
18th January 2011, 07:33
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:



QTextDocument textDocument;
printer->setPageMargins(0.925, 0.8, 0.5, 0.8, QPrinter::Inch); //set page margin

QSizeF paperSize;
paperSize.setWidth(printer->width());
paperSize.setHeight(printer->height());
textDocument.setPageSize(paperSize);

QPainter painter(printer);
textDocument.setHtml(contentFormula); //contentFormula contains some html tags

textDocument.drawContents(&painter);


:) hope this'll be usefull

Cajou
14th October 2011, 09:36
Hello,

you can also use the print() method to print without the page number!
The key is, that the QTextDocument needs a valid pageSize.



QPrinter printer(QPrinter::ScreenResolution);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
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