QwebView Qprinter and pdf
-
I am trying to create a pdf out of my webview, even for simplest html something like this, printer does not save pdf with full page having blue bg color, only hello world has bg color blue rest of the page is white. I tried every thing i could think of but no good, Looks like I am missing something very small , can you please help.
<aa>
<body style=background-color: yellow>
hello world.
</body>
</aa>@
#include <QApplication>
#include <QtPrintSupport>
#include <QtWebKitWidgets>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebView *web = new QWebView();
//web->settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);
web->load(QUrl(myHtmlString))// QDialog dlg; // dlg.exec(); little delay so tht webpage gets loaded QPrinter printer; //printer.setPrinterName("Print to File (PDF)"); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPrintRange(QPrinter::AllPages); printer.setOrientation(QPrinter::Portrait);
// printer.setPaperSize(QSize(400,800),QPrinter::DevicePixel);
printer.setPaperSize(QPrinter::A4);
printer.setResolution(QPrinter::HighResolution);
printer.setFullPage(true);
//printer.setFromTo(0,0);printer.setOutputFileName("myPdfFile.pdf");
// web->page()->setViewportSize(QSize(400,600));
// QWebFrame *frame= web->page()->mainFrame();
//web->page()->setViewportSize(web->page()->mainFrame()->contentsSize());
//web->settings()->setAttribute(QWebSettings::PrintElementBackgrounds, true);// web->resize(frame->contentsSize());
//frame->print(&printer); web->print(&printer); web->show(); return a.exec();
}
@