Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Printing large text on multiple pages

Printing large text on multiple pages

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 304 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    R. Kagirov
    wrote on last edited by
    #1

    Hello everyone,
    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?

    My snippet:

    //...
    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();
    //...
    
    artwawA 1 Reply Last reply
    0
    • R R. Kagirov

      Hello everyone,
      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?

      My snippet:

      //...
      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();
      //...
      
      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by artwaw
      #2

      @R-Kagirov Hi,
      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.

      For more information please re-read.

      Kind Regards,
      Artur

      1 Reply Last reply
      4
      • R Offline
        R Offline
        R. Kagirov
        wrote on last edited by R. Kagirov
        #3

        It works. Thank you.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved