[Qt-interest] QWebView print PDF file only from a QPrintDialog interface
Sorin Lazarescu
Sorin.Lazarescu at jdsu.com
Mon Nov 23 17:25:48 CET 2009
Hi everybody
I have a small QT application that is printing an HTML file to PDF file.
In Qt the QWebView class could print easily the HTML report file after
loading it using a QPrintDialog class. That is perfect as QPrintDialog
let you chose a printer or a PDF file to print but I want to
automatically print to PDF file without forcing the user to pass through
QPrintDialog interface as the name and path of the PDF file is already
know. I understood that this is possible by setting QPrinter properties
programmatically but until now what I get is only a blank PDF page.
Some basic functionality is done under the hood by the QPrintDialog when
used as the PDF ouput file is correctly printed.
Here is my small example that shows the differences in code between
these two cases.
QWebView *web = new QWebView();
web->load(QUrl(fileHTMLReport));
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer);
if ( dialog->exec() == QDialog::Accepted)
web->print(&printer);
So above if I select PDF output into QPrintDialog window and I could see
the output PDF file but setting QPrinter parameters below result in an
empty PDF file as output and the time to get printing out is much
faster?
QWebView *web = new QWebView();
web->load(QUrl(fileHTMLReport));
QPrinter printer;
printer.setPrinterName("Print to File (PDF)");
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPrintRange(QPrinter::AllPages);
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
printer.setResolution(QPrinter::HighResolution);
printer.setFullPage(false);
printer.setNumCopies(1);
printer.setOutputFileName("printYou.pdf");
web->print(&printer);
What do I miss here?
Sorin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/367eab82/attachment.html
More information about the Qt-interest-old
mailing list