From af2535018b1553e351198f3d9c21538de1c328a1 Mon Sep 17 00:00:00 2001 From: Michael Bruning Date: Wed, 10 Aug 2016 17:22:05 +0200 Subject: Add widgets API for printing on a QPrinter Renders the content to a PDF document and then renders this on a QPrinter-backed QPainter using the PDFium library. PDFium bitmap to QImage conversion based on work by Paulo Pinheiro . [ChangeLog][QtWebEngineWidgets][Printing] Enables printing QWebPage content on a QPrinter. Currently does not support previewing the document. Widgets only for the moment. Change-Id: I9a5264433093379aee90f5e4f69bf2aee8814f2b Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/webenginewidgets/api/qwebenginepage.cpp') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index c180699f3..428cccd9a 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -373,6 +373,13 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &re m_callbacks.invoke(requestId, result); } +#ifndef QT_NO_PRINTER +void QWebEnginePagePrivate::didPrintPageOnPrinter(quint64 requestId, bool result) +{ + m_callbacks.invoke(requestId, result); +} +#endif + void QWebEnginePagePrivate::passOnFocus(bool reverse) { if (view) @@ -1841,6 +1848,28 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback &res d->m_callbacks.registerCallback(requestId, resultCallback); } +#ifndef QT_NO_PRINTER +/*! + \fn void QWebEnginePage::print(const QPrinter &printer, FunctorOrLambda resultCallback) + Renders the current content of the page into a temporary PDF document, then prints it using \a printer. + + The settings for creating and printing the PDF document will be retrieved from the \a printer + object. + It is the users responsibility to ensure the \a printer remains valid until \a resultCallback + has been called. + + The \a resultCallback must take a boolean as parameter. If printing was successful, this + boolean will have the value \c true, otherwise, its value will be \c false. + \since 5.8 +*/ +void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback &resultCallback) +{ + Q_D(QWebEnginePage); + quint64 requestId = d->adapter->printOnPrinterCallbackResult(printer); + d->m_callbacks.registerCallback(requestId, resultCallback); +} +#endif // QT_NO_PRINTER + /*! \since 5.7 -- cgit v1.2.3