How to know end of page?



  • I'm using QPainter and QPrinter to print PDF file. Let say, I'm using drawText() to paint a very long paragraph, how to know it has reach the bottom of the page and create a new page?



  • QPrinter provides a pageRect() and paperRect() which you can compare against QFontMetrics of the QPainter opened on the printer instance.
    I generally recommend reading the "printing with qt" tutorial of the Qt Documentation:
    http://doc.qt.digia.com/qt/printing.html

    Note that for printing something that could be called a text document you'll probably have an easier life by using QTextDocument and maybe extending it (own layouts, inline elements, etc.). It already brings pagination of content and printing capabilities.



  • Thanks for the answer. I've already use QTextDocument, but have some problem when printing image file. That's why I try to use QPainter instead.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.