Home > Blockchain >  Print out each content in a separate page use QTextdocument in Qt C
Print out each content in a separate page use QTextdocument in Qt C

Time:06-19

I am a newbie in Qt c . I use QTextdocment to print PDF format. My QTextdocment (doc) is quite long, it consists of separate content. So how can I print out each content in a separate page.

QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setPaperSize(QPrinter::A4);
    printer.setOrientation(QPrinter::Landscape);
    printer.setOutputFileName(ui->lE_Save->text()  ".pdf");
    doc.setDocumentMargin(0);
    doc.setTextWidth(0.5);
    doc.print(&printer);

Thank you.

CodePudding user response:

Thank to all of you. I got the solution to export the contents page by page in PDF format. My code something like that:

QPrinter printer(QPrinter::HighResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    QPageSize pageSize(QPageSize::A4);
    QPainter painter;
    painter.begin(&printer);
    for...
    {
    QTextDocument doc;
            QTextCursor cursor(&doc);

    ...do something for QTextDocument ...

     doc.drawContents(&painter);
            if(page!=monthCount-1)
                printer.newPage();
    }
    painter.end();
  • Related