QWebEnginePage::printToPdf creates empy page
Solved
QtWebEngine
-
My Html2Pdf program:
int main(int argc, char *argv[]) { QApplication app(argc, argv); // arguments QString inputPath = argv[1]; QString outputPath = argv[2]; // read input file QFile inputFile(inputPath); inputFile.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in(&inputFile); QString html = in.readAll(); // get input file directory QFileInfo inputFileInfo(inputFile); QDir inputFileDir = inputFileInfo.dir(); // prepare page QWebEnginePage page; QObject::connect(&page, &QWebEnginePage::pdfPrintingFinished, []{exit(0);}); page.setHtml(html, inputFileDir.path()); //print page page.printToPdf(outputPath); return app.exec(); }
And it doesn't work. It produces pdf file containing one empy page. What do I do wrong?
-
@Tarae My guess is: you need to wait until the HTML page is loaded.
https://doc.qt.io/qt-5/qwebenginepage.html#loadFinished -