Printing large text on multiple pages
R. Kagirov last edited by
I'm developing a program for printing plain text. My code works successfully with small text. However, with large text, only the first page is printed and the last line is cropped.
How to predict which part of the text will be the last on a page in order to continue printing this text on the next page?
//... QPrinter *printer = paramParser.getPrinter(); painter.begin(printer); QFile file(path); file.open(QIODevice::ReadOnly); QString text = QString::fromUtf8(file.readAll()); file.close(); painter.drawText(contentArea,text); painter.end(); //...
artwaw last edited by artwaw
the simplest way would be to wrap up your text in QTextDocument (there is a setter for plain text too), init the printer as usual and use QTextDocument::drawContents() - this way you don't need to worry about pagination, it is all done for you.
Edit: corrected a typo.
R. Kagirov last edited by R. Kagirov
It works. Thank you.