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. How to start a new page in PDF?
QtWS25 Last Chance

How to start a new page in PDF?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k Views
  • 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.
  • C Offline
    C Offline
    canavaroski90
    wrote on last edited by
    #1

    Hi all,

    In my project I'm usign QTextEdit object to write data in it and QPrinter object to write all the data resides in the QTextEdit to a PDF file. Problem is about tables, I can add tables to QTextEdit, however, when QPrint is writing them to file it can seperate tables to 2 pages. In example, lets say there is a table with 10 rows and the cursor is located somewhere near to the bottom of the first page. When QPrinter tries to write the table, it writes first 2 rows to the end of the first page and writes other rows to the following (here is second) page. But I want to write 1 table for 1 page. How can I add something like page seperator (or something like new page)?

    Here is writer portion of the code
    @QPrinter printer;
    printer.setFullPage(true);
    printer.setPaperSize(QPrinter::A4);
    printer.setOrientation(QPrinter::Portrait);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(file_path);
    textEdit->document()->print(&printer);@

    Regards.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Triggering the printer to start a new page is easy: simply call printer::newPage().

      Making QTextEdit do that at the moment you want it to is a completely different, and much more complicated issue. QTextEdit is really focussed on doing a layout of a document as a single page. We ended up not using it for our reporting needs and instead implemented our own report engine based on QML templates.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        canavaroski90
        wrote on last edited by
        #3

        Hi Andre,
        Thanks for your reply. I've solved the problem by using a QPainter object.

        1 Reply Last reply
        0
        • sonu99S Offline
          sonu99S Offline
          sonu99
          wrote on last edited by
          #4

          Hi canavaroski,
          I have the similar problem and I am stuck from last 4 days.
          Pease tell me where I'm going wrong. here is my coding for converting html to pdf.
          Thanking you in advance..!!

          app = QApplication(sys.argv)

          web = QWebView()
          web.load(QUrl("file:///home/reshma/workspace/demo/output/filPlateReport.html"))

          printer = QPrinter()
          printer = QPrinter(QPrinterInfo.defaultPrinter(),QPrinter.HighResolution) # QtGui.QPrinter(QtGui.QPrinter.HighResolution)
          printer.setOutputFormat(QPrinter.PdfFormat)
          printer.newPage()

          printer.setOrientation(QPrinter.Portrait)
          printer.setPageSize(QPrinter.A4)
          printer.setPageMargins (10,10,10,10,QPrinter.Millimeter)

          printer.setFullPage(False)
          printer.setColorMode(QPrinter.Color)

          printer.setOutputFileName("output/Report.pdf")

          def convertIt():
          web.print_(printer)
          print "Pdf Generated"
          QApplication.exit()
          QObject.connect(web, SIGNAL("loadFinished(bool)"),convertIt)

          sys.exit(app.exec_())

          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