From 0887e880ced988704559505816b520972e6876c6 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 8 Jun 2021 13:11:55 +0200 Subject: Add QPageRanges to PDF printing Pick-to: 6.2 Task-number: QTBUG-73497 Change-Id: I0a66c4f1767c54b0bcc9f9a3b61e29c43ec20177 Reviewed-by: Michal Klocek --- src/webenginewidgets/api/qwebengineview.cpp | 15 +++++++++------ src/webenginewidgets/api/qwebengineview.h | 9 +++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src/webenginewidgets/api') diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index b2eb17ec7..8a3ce81a0 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -963,7 +963,8 @@ QWebEngineContextMenuRequest *QWebEngineView::lastContextMenuRequest() const Renders the current content of the page into a PDF document and saves it in the location specified in \a filePath. The page size and orientation of the produced PDF document are taken from - the values specified in \a pageLayout. + the values specified in \a pageLayout, while the range of pages printed is + taken from \a ranges with the default being printing all pages. This method issues an asynchronous request for printing the web page into a PDF and returns immediately. @@ -974,7 +975,7 @@ QWebEngineContextMenuRequest *QWebEngineView::lastContextMenuRequest() const \since 6.2 \sa pdfPrintingFinished() */ -void QWebEngineView::printToPdf(const QString &filePath, const QPageLayout &layout) +void QWebEngineView::printToPdf(const QString &filePath, const QPageLayout &layout, const QPageRanges &ranges) { #if QT_CONFIG(webengine_printing_and_pdf) Q_D(QWebEngineView); @@ -983,7 +984,7 @@ void QWebEngineView::printToPdf(const QString &filePath, const QPageLayout &layo return; } page()->d_ptr->ensureInitialized(); - page()->d_ptr->adapter->printToPDF(layout, filePath); + page()->d_ptr->adapter->printToPDF(layout, ranges, filePath); #else Q_UNUSED(filePath); Q_UNUSED(layout); @@ -993,7 +994,8 @@ void QWebEngineView::printToPdf(const QString &filePath, const QPageLayout &layo /*! Renders the current content of the page into a PDF document and returns a byte array containing the PDF data as parameter to \a resultCallback. - The page size and orientation of the produced PDF document are taken from the values specified in \a pageLayout. + The page size and orientation of the produced PDF document are taken from the values specified in \a pageLayout, + while the range of pages printed is taken from \a ranges with the default being printing all pages. The \a resultCallback must take a const reference to a QByteArray as parameter. If printing was successful, this byte array will contain the PDF data, otherwise, the byte array will be empty. @@ -1004,7 +1006,7 @@ void QWebEngineView::printToPdf(const QString &filePath, const QPageLayout &layo \since 6.2 */ -void QWebEngineView::printToPdf(const QWebEngineCallback &resultCallback, const QPageLayout &layout) +void QWebEngineView::printToPdf(const QWebEngineCallback &resultCallback, const QPageLayout &layout, const QPageRanges &ranges) { Q_D(QWebEngineView); #if QT_CONFIG(webengine_printing_and_pdf) @@ -1014,7 +1016,7 @@ void QWebEngineView::printToPdf(const QWebEngineCallback &res return; } page()->d_ptr->ensureInitialized(); - quint64 requestId = page()->d_ptr->adapter->printToPDFCallbackResult(layout); + quint64 requestId = page()->d_ptr->adapter->printToPDFCallbackResult(layout, ranges); d->m_callbacks.registerCallback(requestId, resultCallback); #else Q_UNUSED(layout); @@ -1072,6 +1074,7 @@ void QWebEngineView::print(QPrinter *printer) d->currentPrinter = printer; page()->d_ptr->ensureInitialized(); page()->d_ptr->adapter->printToPDFCallbackResult(printer->pageLayout(), + printer->pageRanges(), printer->colorMode() == QPrinter::Color, false); #else diff --git a/src/webenginewidgets/api/qwebengineview.h b/src/webenginewidgets/api/qwebengineview.h index 3faa07a6b..b43552211 100644 --- a/src/webenginewidgets/api/qwebengineview.h +++ b/src/webenginewidgets/api/qwebengineview.h @@ -41,6 +41,7 @@ #define QWEBENGINEVIEW_H #include +#include #include #include @@ -109,8 +110,12 @@ public: #endif QWebEngineContextMenuRequest *lastContextMenuRequest() const; - void printToPdf(const QString &filePath, const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF())); - void printToPdf(const QWebEngineCallback &resultCallback, const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF())); + void printToPdf(const QString &filePath, + const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()), + const QPageRanges &ranges = {}); + void printToPdf(const QWebEngineCallback &resultCallback, + const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()), + const QPageRanges &ranges = {}); void print(QPrinter *printer); public Q_SLOTS: -- cgit v1.2.3