summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-08 13:11:55 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-22 08:14:38 +0200
commit0887e880ced988704559505816b520972e6876c6 (patch)
tree0f6034bf51713560b8576970572371458a05c05e /src/webenginewidgets
parentf17231b7a1ac1c1cfd2798cc57315a5d41a7df31 (diff)
Add QPageRanges to PDF printing
Pick-to: 6.2 Task-number: QTBUG-73497 Change-Id: I0a66c4f1767c54b0bcc9f9a3b61e29c43ec20177 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebengineview.cpp15
-rw-r--r--src/webenginewidgets/api/qwebengineview.h9
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: