Creating a PDF from qwebview does not include images

I am creating a PDF file from QWebView.

class myView: public QWebView { } 

One of the member functions has:

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

I see that the pdf file is generated, but in the html file there are several images that are not entering the pdf, it is empty.

Surfing the net did not help, and I also included WebSetting, for example:

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

Can someone kindly suggest that I am missing?

+4
source share
2 answers

You must first tell the print to wait, showing page loading so you

  • add this to your code:

     connect(&document, SIGNAL(loadFinished(bool)), SLOT(printpdf())); 

where the document is your qwebview variable;

  1. then you create your private slot:

     printpdf(); 

in this function you have to call the printer and print (& printer);

don't forget , in your html in scr you have to add the file: ///

Example

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

Using the "printpdf" slot, I got a PDF file, however, when I update the image in my HTML code and redraw, the old image is still displayed.

Any suggestions?

0
source

All Articles