diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-08 13:11:55 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-22 14:23:30 +0000 |
commit | a693cae520455ece9bf860ab2804f03d465d51af (patch) | |
tree | 530c06f750c0554af3e46f368be96f7fe80cadb2 /src/webenginewidgets | |
parent | 3752a3cbcd0cc0742a5b955e925df18395afdb75 (diff) |
Add QPageRanges to PDF printing
Task-number: QTBUG-73497
Change-Id: I0a66c4f1767c54b0bcc9f9a3b61e29c43ec20177
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
(cherry picked from commit 0887e880ced988704559505816b520972e6876c6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r-- | src/webenginewidgets/api/qwebengineview.cpp | 15 | ||||
-rw-r--r-- | src/webenginewidgets/api/qwebengineview.h | 9 |
2 files changed, 16 insertions, 8 deletions
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<const QByteArray&> &resultCallback, const QPageLayout &layout) +void QWebEngineView::printToPdf(const QWebEngineCallback<const QByteArray&> &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<const QByteArray&> &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 <QtGui/qpainter.h> +#include <QtGui/qpageranges.h> #include <QtNetwork/qnetworkaccessmanager.h> #include <QtWidgets/qwidget.h> @@ -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<const QByteArray&> &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<const QByteArray&> &resultCallback, + const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF()), + const QPageRanges &ranges = {}); void print(QPrinter *printer); public Q_SLOTS: |