从qwebview生成PDF不包括图像

时间:2013-04-23 12:11:54

标签: qt

我正在从QWebView创建pdf文件。

class myView: public QWebView
{
}

其中一个成员函数有:

 this->settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);
 QPrinter printer;
 printer.setOutputFormat(QPrinter::PdfFormat);
 printer.setResolution(QPrinter::HighResolution);
 printer.setOutputFileName("whoami.pdf");
 print(&printer);

我看到生成了pdf文件,但是html文件中没有很少的图像 进入pdf,它是空白的。

网上冲浪没什么用,我也启用了WebSetting,如:

 this->settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);

有人可以建议我缺少什么吗?

1 个答案:

答案 0 :(得分:1)

你应该首先说打印等待告诉页面加载所以你应该

  1. 将此内容添加到您的代码中:

    connect(&document, SIGNAL(loadFinished(bool)), SLOT(printpdf()));
    
  2. 其中document是你的qwebview变量;

    1. 然后您创建私人广告位:

      printpdf();
      
    2. 在此功能中,您应该调用打印机并打印(& printer);

      别忘了, 在您的HTML中,在scr中你应该添加file:///

      例证

      <img src="file:///c:/image.jpg" />