[ Solved] Print QWebView to PDF
-
[ Solved] Had as typo in the location string - sorry for bothering!
I want to print an already loaded string containing HTML source code to PDF.
So here's the function I implemented:// Print to PDF // Purpose: print incoming HTML source code to a PDF on the users desktop // Input: string containing the HTML source code, string with the desired filename of resulting PDF // Output: void void MainWindow::printToPDF(QString htmlinput, QString filename) { // Set location of resulting PDF QString saveLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/" + filename + ".pdf"; // Initialize printer and set save location QPrinter printer(QPrinter::HighResolution); printer.setOutputFileName(saveLocation); // Create webview and load html source QWebView webview; webview.setHtml(htmlinput); // Create PDF webview.print(&printer); }
Unfortunately it results in the following error and no PDF is created:
QPainter::begin(): Returned false
By the way, the newby I am I confirmed the techniques used in the function in another project and it worked fine there.
Any suggestions? Thanks for all your efforts in advance!