the QT application I'm working on comes with a tutorial. Each chapter is a separate HTML file, each file can span several pages. Now I want to print them into a single PDF file (with page numbers).
My naive approach was this, but it is wrong:
#include <QApplication>
#include <QPrinter>
#include <QTextBrowser>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPrinter printer;
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("/tmp/test.pdf");
QTextBrowser *tp = new QTextBrowser();
tp->setSource(QUrl("qrc:///help/tutorial_item_1.html"));
tp->print(&printer);
tp->setSource(QUrl("qrc:///help/tutorial_item_2.html"));
tp->print(&printer);
tp->setSource(QUrl("qrc:///help/tutorial_item_3.html"));
tp->print(&printer);
}
However, this will restart the printer on every call print(), starting with a new PDF file, overwriting the old one.
What is a simple solution to print all HTML into a single PDF using QT?
source
share