QWebView prints PDF file OK with QPrintDialog only
Hi
I have a small application where I create a report in HTML format that must be shown, print to printer or saved to a PDF file.
I could save the HTML report file as a PDF file if I use the QPrintDialog input and select the PDF output but I could not print PDF using only QPrinter and setting QPrinter properties myself in the code. Why is that?
Code:
QWebView *web = new QWebView();
web
->load
(QUrl(fileHTMLReport
));
if ( dialog
->exec
() == QDialog::Accepted) web->print(&printer);
So above if I select PDF output into QPrintDialog window I could save fileHTMLReport in PDF format but if I try to do it without using QPrintDialog by setting only the QPrinter parameters result in an empty PDF file?
Code:
QWebView *web = new QWebView();
web
->load
(QUrl(fileHTMLReport
));
printer.setPrinterName("Print to File (PDF)");
printer.
setOutputFormat(QPrinter::PdfFormat);
printer.
setPrintRange(QPrinter::AllPages);
printer.
setOrientation(QPrinter::Portrait);
printer.
setResolution(QPrinter::HighResolution);
printer.setFullPage(false);
printer.setNumCopies(1);
printer.setOutputFileName("printYou.pdf");
web->print(&printer);
result in "printYou.pdf" file being empty and not showing "fileHTMLReport" file as when printing is done through QPrintDialog interface call?
What do I miss here?
Sorin
Re: QWebView prints PDF file OK with QPrintDialog only
I would say you forget to set some parameter in your code which is responsible for scaling the painter or something like that. It might be easiest if you looked into source code for QPrintDialog to see what exactly gets set by it.
Re: QWebView prints PDF file OK with QPrintDialog only
Hi !
I have exactly the same problem here. Have you found a solution ?
Re: QWebView prints PDF file OK with QPrintDialog only
Hi !
I am here to answer to my problem it could be useful for someone. In fact I just had to connect the loadFinished signal of the QWebView to a method to print. In my code the printing was launched before the end of the page loading which gave me a blank page