summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/webenginewidgets/demobrowser/browsermainwindow.cpp21
-rw-r--r--examples/webenginewidgets/demobrowser/browsermainwindow.h1
-rw-r--r--src/core/web_contents_adapter.cpp13
-rw-r--r--src/core/web_contents_adapter.h3
-rw-r--r--src/webengine/api/qquickwebengineview.cpp12
-rw-r--r--src/webengine/api/qquickwebengineview_p.h161
-rw-r--r--src/webengine/doc/qtwebengine.qdocconf1
-rw-r--r--src/webengine/doc/src/webengineview.qdoc167
-rw-r--r--src/webenginewidgets/api/qwebengineview.cpp5
-rw-r--r--src/webenginewidgets/api/qwebengineview.h5
-rw-r--r--src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc9
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp15
-rw-r--r--tests/auto/widgets/qwebengineview/resources/basic_printing_page.html8
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp21
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.qrc15
15 files changed, 449 insertions, 8 deletions
diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
index 4b53124da..60b69ddd6 100644
--- a/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
+++ b/examples/webenginewidgets/demobrowser/browsermainwindow.cpp
@@ -312,8 +312,12 @@ void BrowserMainWindow::setupMenu()
#if defined(QWEBENGINEPAGE_PRINT)
fileMenu->addAction(tr("P&rint Preview..."), this, SLOT(slotFilePrintPreview()));
fileMenu->addAction(tr("&Print..."), this, SLOT(slotFilePrint()), QKeySequence::Print);
- fileMenu->addSeparator();
#endif
+#ifndef QT_NO_PRINTER
+ fileMenu->addAction(tr("&Print to PDF..."), this, SLOT(slotFilePrintToPDF()));
+#endif // ifndef QT_NO_PRINTER
+ fileMenu->addSeparator();
+
QAction *action = fileMenu->addAction(tr("Private &Browsing..."), this, SLOT(slotPrivateBrowsing()));
action->setCheckable(true);
action->setChecked(BrowserApplication::instance()->privateBrowsing());
@@ -697,6 +701,21 @@ void BrowserMainWindow::slotFilePrint()
#endif
}
+void BrowserMainWindow::slotFilePrintToPDF()
+{
+#ifndef QT_NO_PRINTER
+ if (!currentTab())
+ return;
+ QPrinter printer;
+ QPrintDialog *dialog = new QPrintDialog(&printer, this);
+ dialog->setWindowTitle(tr("Print Document"));
+ if (dialog->exec() != QDialog::Accepted || printer.outputFileName().isEmpty())
+ return;
+
+ currentTab()->printToPDF(printer.outputFileName(), printer.pageLayout());
+#endif // QT_NO_PRINTER
+}
+
#if defined(QWEBENGINEPAGE_PRINT)
void BrowserMainWindow::printRequested(QWebEngineFrame *frame)
{
diff --git a/examples/webenginewidgets/demobrowser/browsermainwindow.h b/examples/webenginewidgets/demobrowser/browsermainwindow.h
index 3f939b367..2e1d178d7 100644
--- a/examples/webenginewidgets/demobrowser/browsermainwindow.h
+++ b/examples/webenginewidgets/demobrowser/browsermainwindow.h
@@ -109,6 +109,7 @@ private slots:
void slotFileOpen();
void slotFilePrintPreview();
void slotFilePrint();
+ void slotFilePrintToPDF();
void slotPrivateBrowsing();
void slotFileSaveAs();
void slotEditFind();
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index eb4436018..2d153130f 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -49,6 +49,7 @@
#include "browser_context_qt.h"
#include "download_manager_delegate_qt.h"
#include "media_capture_devices_dispatcher.h"
+#include "print_view_manager_qt.h"
#include "qwebenginecallback_p.h"
#include "render_view_observer_host_qt.h"
#include "type_conversion.h"
@@ -79,6 +80,7 @@
#include <QDir>
#include <QGuiApplication>
+#include <QPageLayout>
#include <QStringList>
#include <QStyleHints>
#include <QTimer>
@@ -411,6 +413,10 @@ void WebContentsAdapter::initialize(WebContentsAdapterClient *adapterClient)
// This should only be necessary after having restored the history to a new WebContentsAdapter.
d->webContents->GetController().LoadIfNecessary();
+#if defined(ENABLE_BASIC_PRINTING)
+ PrintViewManagerQt::CreateForWebContents(webContents());
+#endif // defined(ENABLE_BASIC_PRINTING)
+
// Create a RenderView with the initial empty document
content::RenderViewHost *rvh = d->webContents->GetRenderViewHost();
Q_ASSERT(rvh);
@@ -897,6 +903,13 @@ void WebContentsAdapter::wasHidden()
d->webContents->WasHidden();
}
+void WebContentsAdapter::printToPDF(const QPageLayout &pageLayout, const QString &filePath)
+{
+#if defined(ENABLE_BASIC_PRINTING)
+ PrintViewManagerQt::FromWebContents(webContents())->PrintToPDF(pageLayout, filePath);
+#endif // if defined(ENABLE_BASIC_PRINTING)
+}
+
QPointF WebContentsAdapter::lastScrollOffset() const
{
Q_D(const WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index c7c2c1edf..44f50e429 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE
class QAccessibleInterface;
class QDragEnterEvent;
class QDragMoveEvent;
+class QPageLayout;
+class QString;
class QWebChannel;
QT_END_NAMESPACE
@@ -169,6 +171,7 @@ public:
void endDragging(const QPoint &clientPos, const QPoint &screenPos);
void leaveDrag();
void initUpdateDragCursorMessagePollingTimer();
+ void printToPDF(const QPageLayout&, const QString&);
// meant to be used within WebEngineCore only
content::WebContents *webContents() const;
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 70a85f5f3..742cd6cf8 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -70,7 +70,10 @@
#include <QClipboard>
#include <QGuiApplication>
#include <QLoggingCategory>
+#include <QMarginsF>
#include <QMimeData>
+#include <QPageLayout>
+#include <QPageSize>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlEngine>
@@ -1179,6 +1182,15 @@ bool QQuickWebEngineView::wasRecentlyAudible()
return d->adapter->wasRecentlyAudible();
}
+void QQuickWebEngineView::printToPDF(const QString &filePath, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation)
+{
+ Q_D(QQuickWebEngineView);
+ QPageSize layoutSize(static_cast<QPageSize::PageSizeId>(pageSizeId));
+ QPageLayout::Orientation layoutOrientation = static_cast<QPageLayout::Orientation>(orientation);
+ QPageLayout pageLayout(layoutSize, layoutOrientation, QMarginsF(0.0, 0.0, 0.0, 0.0));
+ d->adapter->printToPDF(pageLayout, filePath);
+}
+
bool QQuickWebEngineView::isFullScreen() const
{
Q_D(const QQuickWebEngineView);
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 4c6cbbaff..9433a2150 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -273,6 +273,166 @@ public:
};
Q_DECLARE_FLAGS(FindFlags, FindFlag)
+ // must match QPageSize::PageSizeId
+ enum PrintedPageSizeId {
+ // Existing Qt sizes
+ A4,
+ B5,
+ Letter,
+ Legal,
+ Executive,
+ A0,
+ A1,
+ A2,
+ A3,
+ A5,
+ A6,
+ A7,
+ A8,
+ A9,
+ B0,
+ B1,
+ B10,
+ B2,
+ B3,
+ B4,
+ B6,
+ B7,
+ B8,
+ B9,
+ C5E,
+ Comm10E,
+ DLE,
+ Folio,
+ Ledger,
+ Tabloid,
+ Custom,
+
+ // New values derived from PPD standard
+ A10,
+ A3Extra,
+ A4Extra,
+ A4Plus,
+ A4Small,
+ A5Extra,
+ B5Extra,
+
+ JisB0,
+ JisB1,
+ JisB2,
+ JisB3,
+ JisB4,
+ JisB5,
+ JisB6,
+ JisB7,
+ JisB8,
+ JisB9,
+ JisB10,
+
+ // AnsiA = Letter,
+ // AnsiB = Ledger,
+ AnsiC,
+ AnsiD,
+ AnsiE,
+ LegalExtra,
+ LetterExtra,
+ LetterPlus,
+ LetterSmall,
+ TabloidExtra,
+
+ ArchA,
+ ArchB,
+ ArchC,
+ ArchD,
+ ArchE,
+
+ Imperial7x9,
+ Imperial8x10,
+ Imperial9x11,
+ Imperial9x12,
+ Imperial10x11,
+ Imperial10x13,
+ Imperial10x14,
+ Imperial12x11,
+ Imperial15x11,
+
+ ExecutiveStandard,
+ Note,
+ Quarto,
+ Statement,
+ SuperA,
+ SuperB,
+ Postcard,
+ DoublePostcard,
+ Prc16K,
+ Prc32K,
+ Prc32KBig,
+
+ FanFoldUS,
+ FanFoldGerman,
+ FanFoldGermanLegal,
+
+ EnvelopeB4,
+ EnvelopeB5,
+ EnvelopeB6,
+ EnvelopeC0,
+ EnvelopeC1,
+ EnvelopeC2,
+ EnvelopeC3,
+ EnvelopeC4,
+ // EnvelopeC5 = C5E,
+ EnvelopeC6,
+ EnvelopeC65,
+ EnvelopeC7,
+ // EnvelopeDL = DLE,
+
+ Envelope9,
+ // Envelope10 = Comm10E,
+ Envelope11,
+ Envelope12,
+ Envelope14,
+ EnvelopeMonarch,
+ EnvelopePersonal,
+
+ EnvelopeChou3,
+ EnvelopeChou4,
+ EnvelopeInvite,
+ EnvelopeItalian,
+ EnvelopeKaku2,
+ EnvelopeKaku3,
+ EnvelopePrc1,
+ EnvelopePrc2,
+ EnvelopePrc3,
+ EnvelopePrc4,
+ EnvelopePrc5,
+ EnvelopePrc6,
+ EnvelopePrc7,
+ EnvelopePrc8,
+ EnvelopePrc9,
+ EnvelopePrc10,
+ EnvelopeYou4,
+
+ // Last item, with commonly used synynoms from QPagedPrintEngine / QPrinter
+ LastPageSize = EnvelopeYou4,
+ NPageSize = LastPageSize,
+ NPaperSize = LastPageSize,
+
+ // Convenience overloads for naming consistency
+ AnsiA = Letter,
+ AnsiB = Ledger,
+ EnvelopeC5 = C5E,
+ EnvelopeDL = DLE,
+ Envelope10 = Comm10E
+ };
+ Q_ENUM(PrintedPageSizeId)
+
+ // must match QPageLayout::Orientation
+ enum PrintedPageOrientation {
+ Portrait,
+ Landscape
+ };
+ Q_ENUM(PrintedPageOrientation)
+
// QmlParserStatus
virtual void componentComplete() Q_DECL_OVERRIDE;
@@ -312,6 +472,7 @@ public Q_SLOTS:
Q_REVISION(3) bool isAudioMuted() const;
Q_REVISION(3) void setAudioMuted(bool muted);
Q_REVISION(3) bool wasRecentlyAudible();
+ Q_REVISION(3) void printToPDF(const QString &filePath, PrintedPageSizeId pageSizeId = PrintedPageSizeId::A4, PrintedPageOrientation orientation = PrintedPageOrientation::Portrait);
private Q_SLOTS:
void lazyInitialize();
diff --git a/src/webengine/doc/qtwebengine.qdocconf b/src/webengine/doc/qtwebengine.qdocconf
index 2fbdef93e..d2b8980c4 100644
--- a/src/webengine/doc/qtwebengine.qdocconf
+++ b/src/webengine/doc/qtwebengine.qdocconf
@@ -43,6 +43,7 @@ tagfile = ../../../doc/qtwebengine/qtwebengine.tags
depends += qtcore \
qtgui \
qtnetwork \
+ qtprintsupport \
qtqml \
qtquick \
qtquickcontrols \
diff --git a/src/webengine/doc/src/webengineview.qdoc b/src/webengine/doc/src/webengineview.qdoc
index 8e09d2b89..6a4e2ffef 100644
--- a/src/webengine/doc/src/webengineview.qdoc
+++ b/src/webengine/doc/src/webengineview.qdoc
@@ -717,6 +717,165 @@
*/
/*!
+ \qmlproperty enumeration WebEngineView::PrintedPageSizeId
+ \since QtWebEngine 1.3
+
+ This enum type lists the available page sizes as defined in the Postscript
+ PPD standard.
+
+ The enumeration values are mapped from and must match QPageSize::PageSizeId. They are also
+ duplicated in QPagedPaintDevice and QPrinter.
+
+ The defined sizes are:
+
+ \value A0 841 x 1189 mm
+ \value A1 594 x 841 mm
+ \value A2 420 x 594 mm
+ \value A3 297 x 420 mm
+ \value A4 210 x 297 mm, 8.26 x 11.69 inches
+ \value A5 148 x 210 mm
+ \value A6 105 x 148 mm
+ \value A7 74 x 105 mm
+ \value A8 52 x 74 mm
+ \value A9 37 x 52 mm
+ \value B0 1000 x 1414 mm
+ \value B1 707 x 1000 mm
+ \value B2 500 x 707 mm
+ \value B3 353 x 500 mm
+ \value B4 250 x 353 mm
+ \value B5 176 x 250 mm, 6.93 x 9.84 inches
+ \value B6 125 x 176 mm
+ \value B7 88 x 125 mm
+ \value B8 62 x 88 mm
+ \value B9 44 x 62 mm
+ \value B10 31 x 44 mm
+ \value C5E 163 x 229 mm
+ \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
+ \value DLE 110 x 220 mm
+ \value Executive 7.5 x 10 inches, 190.5 x 254 mm
+ \value Folio 210 x 330 mm
+ \value Ledger 431.8 x 279.4 mm
+ \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
+ \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
+ \value Tabloid 279.4 x 431.8 mm
+ \value Custom Unknown, or a user defined size.
+ \value A10
+ \value A3Extra
+ \value A4Extra
+ \value A4Plus
+ \value A4Small
+ \value A5Extra
+ \value B5Extra
+ \value JisB0
+ \value JisB1
+ \value JisB2
+ \value JisB3
+ \value JisB4
+ \value JisB5
+ \value JisB6
+ \value JisB7
+ \value JisB8
+ \value JisB9
+ \value JisB10
+ \value AnsiA = \c Letter
+ \value AnsiB = \c Ledger
+ \value AnsiC
+ \value AnsiD
+ \value AnsiE
+ \value LegalExtra
+ \value LetterExtra
+ \value LetterPlus
+ \value LetterSmall
+ \value TabloidExtra
+ \value ArchA
+ \value ArchB
+ \value ArchC
+ \value ArchD
+ \value ArchE
+ \value Imperial7x9
+ \value Imperial8x10
+ \value Imperial9x11
+ \value Imperial9x12
+ \value Imperial10x11
+ \value Imperial10x13
+ \value Imperial10x14
+ \value Imperial12x11
+ \value Imperial15x11
+ \value ExecutiveStandard
+ \value Note
+ \value Quarto
+ \value Statement
+ \value SuperA
+ \value SuperB
+ \value Postcard
+ \value DoublePostcard
+ \value Prc16K
+ \value Prc32K
+ \value Prc32KBig
+ \value FanFoldUS
+ \value FanFoldGerman
+ \value FanFoldGermanLegal
+ \value EnvelopeB4
+ \value EnvelopeB5
+ \value EnvelopeB6
+ \value EnvelopeC0
+ \value EnvelopeC1
+ \value EnvelopeC2
+ \value EnvelopeC3
+ \value EnvelopeC4
+ \value EnvelopeC5 = \c C5E
+ \value EnvelopeC6
+ \value EnvelopeC65
+ \value EnvelopeC7
+ \value EnvelopeDL = \c DLE
+ \value Envelope9
+ \value Envelope10 = \c Comm10E
+ \value Envelope11
+ \value Envelope12
+ \value Envelope14
+ \value EnvelopeMonarch
+ \value EnvelopePersonal
+ \value EnvelopeChou3
+ \value EnvelopeChou4
+ \value EnvelopeInvite
+ \value EnvelopeItalian
+ \value EnvelopeKaku2
+ \value EnvelopeKaku3
+ \value EnvelopePrc1
+ \value EnvelopePrc2
+ \value EnvelopePrc3
+ \value EnvelopePrc4
+ \value EnvelopePrc5
+ \value EnvelopePrc6
+ \value EnvelopePrc7
+ \value EnvelopePrc8
+ \value EnvelopePrc9
+ \value EnvelopePrc10
+ \value EnvelopeYou4
+ \value LastPageSize = \c EnvelopeYou4
+ \omitvalue NPageSize
+ \omitvalue NPaperSize
+
+ \sa WebEngineView::printToPDF()
+*/
+
+/*!
+ \qmlproperty enumeration WebEngineView::PrintedPageOrientation
+ \since QtWebEngine 1.3
+
+ Describes the orientation of a PDF document that gets created from the WebEngineView's contents.
+ The enumeration values are mapped from and must match QPageLayout::Orientation.
+
+ \value Portrait
+ The document will be created using portrait orientation.
+
+ \value Landscape
+ The document will be created using landscape orientation.
+
+ \sa WebEngineView::printToPDF()
+*/
+
+/*!
\qmltype WebEngineFullScreenRequest
\instantiates QQuickWebEngineFullScreenRequest
\inqmlmodule QtWebEngine
@@ -785,6 +944,14 @@
*/
/*!
+ \qmlmethod void WebEngineView::printToPDF(const QString &filePath, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation)
+ \since QtWebEngine 1.3
+
+ Prints the WebEngineView's current contents to a PDF document and stores it under \a filePath. The document's size will be determined
+ by the value of \a pageSizeId and its orientation will be determined using \a orientation.
+*/
+
+/*!
\qmlsignal void WebEngineView::wasRecentlyAudibleChanged(bool wasRecentlyAudible)
\since QtWebEngine 1.3
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp
index 8f2c3cbf7..b40ff2b51 100644
--- a/src/webenginewidgets/api/qwebengineview.cpp
+++ b/src/webenginewidgets/api/qwebengineview.cpp
@@ -51,6 +51,7 @@
#include <QMenu>
#include <QContextMenuEvent>
#include <QStackedLayout>
+#include <QPageLayout>
QT_BEGIN_NAMESPACE
@@ -262,6 +263,10 @@ QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)
return 0;
}
+void QWebEngineView::printToPDF(const QString &filePath, const QPageLayout &pageLayout)
+{
+ page()->d_func()->adapter->printToPDF(pageLayout, filePath);
+}
qreal QWebEngineView::zoomFactor() const
{
diff --git a/src/webenginewidgets/api/qwebengineview.h b/src/webenginewidgets/api/qwebengineview.h
index 7181509d2..30125e575 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/qpagelayout.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtWidgets/qwidget.h>
@@ -49,6 +50,8 @@
QT_BEGIN_NAMESPACE
class QContextMenuEvent;
+class QPageLayout;
+class QString;
class QUrl;
class QWebEnginePage;
class QWebEngineSettings;
@@ -102,6 +105,8 @@ public:
virtual QSize sizeHint() const Q_DECL_OVERRIDE;
QWebEngineSettings *settings() const;
+ void printToPDF(const QString &filePath, const QPageLayout &layout = QPageLayout());
+
public Q_SLOTS:
void stop();
void back();
diff --git a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
index 1ec831ac2..d179e4f2b 100644
--- a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
@@ -254,6 +254,15 @@
*/
/*!
+ \fn void QWebEngineView::printToPDF(const QString &filePath, const QPageLayout &layout)
+ \since 5.7
+ Renders the current contents of the view 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 layout.
+
+ If a file already exists at the provided file path, it will be overwritten.
+*/
+
+/*!
\fn void QWebEngineView::stop()
Convenience slot that stops loading the document.
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index a1900a77d..4430bdae0 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -60,6 +60,7 @@ private Q_SLOTS:
void inputMethod();
void inputMethodHints();
void basicRenderingSanity();
+ void printToPDF();
private:
inline QQuickWebEngineView *newWebEngineView();
@@ -461,5 +462,19 @@ void tst_QQuickWebEngineView::inputMethodHints()
#endif
}
+void tst_QQuickWebEngineView::printToPDF()
+{
+ QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX");
+ QVERIFY(tempDir.isValid());
+ QQuickWebEngineView *view = webEngineView();
+ view->setUrl(urlFromTestPath("html/basic_page.html"));
+ QVERIFY(waitForLoadSucceeded(view));
+
+ QString path = tempDir.path() + "/print_success.pdf";
+ view->printToPDF(path, QQuickWebEngineView::A4, QQuickWebEngineView::Portrait);
+ QTest::qWait(500);
+ QVERIFY(QFile::exists(path));
+}
+
QTEST_MAIN(tst_QQuickWebEngineView)
#include "tst_qquickwebengineview.moc"
diff --git a/tests/auto/widgets/qwebengineview/resources/basic_printing_page.html b/tests/auto/widgets/qwebengineview/resources/basic_printing_page.html
new file mode 100644
index 000000000..0c6ff379f
--- /dev/null
+++ b/tests/auto/widgets/qwebengineview/resources/basic_printing_page.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<title> Basic Printing Page </title>
+</head>
+<body>
+<h1>Hello Paper World</h1>
+</body>
+</html>
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 1ebb22cc9..b09e45646 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -23,11 +23,13 @@
#include "../util.h"
#include <qpainter.h>
+#include <qpagelayout.h>
#include <qwebengineview.h>
#include <qwebenginepage.h>
#include <qwebenginesettings.h>
#include <qnetworkrequest.h>
#include <qdiriterator.h>
+#include <qtemporarydir.h>
#define VERIFY_INPUTMETHOD_HINTS(actual, expect) \
QVERIFY(actual == expect);
@@ -59,6 +61,7 @@ private Q_SLOTS:
void setPalette_data();
void setPalette();
#endif
+ void printToPDF();
};
// This will be called before the first test function is executed.
@@ -528,6 +531,24 @@ void tst_QWebEngineView::setPalette()
}
#endif
+void tst_QWebEngineView::printToPDF()
+{
+ QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX");
+ QVERIFY(tempDir.isValid());
+ QWebEngineView view;
+ QUrl url("qrc:///resources/basic_printing_page.html");
+ view.page()->load(url);
+ QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool))));
+ view.show();
+
+ QTest::qWaitForWindowExposed(&view);
+ QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0.0, 0.0, 0.0, 0.0));
+ QString path = tempDir.path() + "/print_success.pdf";
+ view.printToPDF(path, layout);
+ QTest::qWait(500);
+ QVERIFY(QFile::exists(path));
+}
+
void tst_QWebEngineView::renderingAfterMaxAndBack()
{
#if !defined(QWEBENGINEPAGE_RENDER)
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.qrc b/tests/auto/widgets/qwebengineview/tst_qwebengineview.qrc
index 6685a8086..b32b533c2 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.qrc
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.qrc
@@ -1,8 +1,9 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>resources/index.html</file>
- <file>resources/frame_a.html</file>
- <file>resources/input_types.html</file>
- <file>resources/scrolltest_page.html</file>
-</qresource>
+<RCC>
+ <qresource prefix="/">
+ <file>resources/index.html</file>
+ <file>resources/frame_a.html</file>
+ <file>resources/input_types.html</file>
+ <file>resources/scrolltest_page.html</file>
+ <file>resources/basic_printing_page.html</file>
+ </qresource>
</RCC>