QWebFrame print with external style ?
Solved
General and Desktop
-
Hi,
It's possible to print a QWebView -> QWebFrame with an external style style.css?
my output pdf file isn't formated with my style.css file ?QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer); if ( dialog->exec() == QDialog::Accepted) { QWebFrame *frame = m_view->page()->mainFrame(); frame->print(&printer); }
In my html code, there are two include file:
<link rel="stylesheet" href="file:///D:/code/build-mcercle-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/Chart.js/style.css" media="screen"/> <link rel="stylesheet" href="file:///D:/code/build-mcercle-Desktop_Qt_5_5_1_MinGW_32bit-Debug/debug/Chart.js/plucss.css" media="screen"/>
-
Ok to fix it I export view into QImage
void mgraph::onPrintView(QPrinter *printer) { QPainter painter(printer); QWebPage *page = m_view->page(); QWebFrame *frame = page->mainFrame(); // set size of view page->setViewportSize( frame->contentsSize() ); QImage imgView( page->viewportSize(), QImage::Format_ARGB32 ); // set painter for render QPainter painterImage(&imgView); frame->render(&painterImage); painterImage.end(); //Scale image of printer content QImage img = imgView.scaled( printer->pageRect().width(), printer->pageRect().height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); // Draw rescaled image to painter of printer painter.drawImage(QPoint(0,0), img); painter.end(); }