【发布时间】:2015-08-21 04:44:15
【问题描述】:
我想将 QWebView 打印为 PDF 并将其保存在桌面上。 为此我实现了一个函数,代码如下:
// 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);
}
现在我的问题是我的应用程序中出现以下错误:
QPainter::begin(): Returned false
我可以确认此错误是由上述函数引起的,另一方面,我仅在另一个项目中尝试了上述代码以确认它有效 - 它确实有效。
有什么建议吗?
【问题讨论】:
标签: c++ qt pdf qwebview qprinter