PDA

View Full Version : with pdf printer.newPage() fails everytime



MWagman
29th January 2013, 23:36
Trying to write a function that you pass a QStringList to, and a file name - creates a multiple page PDF - each string list holding HTML for that page.

Here is my code always creates the last page as the only page with page 1 in the corner , new page returns false every time


void pmdUtility::pmdMakePdf(QStringList oPages,QString qsFileName)
{
QPrinter printer;
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
printer.setResolution(300);
printer.setFullPage(false);
printer.setCopyCount(1);
printer.setColorMode(QPrinter::Color);

printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(qsFileName);
QRect Rect1(0.0,0.0,printer.width(),printer.height());
foreach (QString qsPage, oPages)
{
printer.newPage();

QTextDocument document;
document.setHtml(qsPage);
document.print(&printer);
}
}

MWagman
11th February 2013, 18:30
You can put one HTML page into a QTextDocument - you need to tell the HTML to parse the pages

<DIV style="page-break-after:always"></DIV>