How to start a new page in PDF?



  • 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.



  • 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.



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



  • 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_())


Log in to reply
 

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