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?
QWebView *web = new QWebView();
web
->load
(QUrl(fileHTMLReport
));
if ( dialog
->exec
() == QDialog::Accepted) web->print(&printer);
QWebView *web = new QWebView();
web->load(QUrl(fileHTMLReport));
QPrinter printer;
QPrintDialog *dialog = new QPrintDialog(&printer);
if ( dialog->exec() == QDialog::Accepted)
web->print(&printer);
To copy to clipboard, switch view to plain text mode
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?
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);
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);
To copy to clipboard, switch view to plain text mode
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
Bookmarks