[Qt-interest] Printing a (local) webpage with images

Mathias Waack Mathias.Waack at rantzau.de
Tue May 31 20:44:54 CEST 2011


QTextDocument could be a solution, thanks Jason. It doesn't work for us 
because we're using some css features not supported there. 
We've solved this issue by creating a dialog containing the QWebView. If we 
print the QWebview from this dialog (in a slot connected to loadFinished) it 
works fine. Its an ugly workaround but it works for us. 

Mathias

PS: I consider this an ugly workaround because I assume we've just "solved" 
the async-load-problem by spending more time in the event loop. So the main 
question remains: how can I check whether an external object is loaded?

On Thursday, May 26, 2011 04:35:12 PM Mathias Waack wrote:
> Hi all,
> 
> I'm trying to print a webpage. The problem is (at least from my
> understanding) this fact:
> 
> [see QWebFrame::setContent]
> The data is loaded immediately; external objects are loaded asynchronously.
> 
> If I print the page directly like this:
> 
> QWebView *view = ...;
> view->setHtml(... /* a QString containing some <img src="file://...">
> tags*/); QPrinter printer;
> printer.setPageMargins(20,5,5,5,QPrinter::Millimeter);
> printer.setOutputFileName(pdfFileName);
> printer.setOutputFormat(QPrinter::PdfFormat);
> printer.setPageSize(QPrinter::A4);
> view.print(&printer);
> 
> in some cases some images are missing on the pdf. Thus I assume the problem
> is the above sentence. Even waiting for the "void loadFinished(bool ok)"
> signal does not solve my problem.
> 
> I there a way to ensure all external objects in the page are loaded and the
> document is ready for printout?
> 
> Thanks!
> 
> Mathias
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list