Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpdfdocument.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPDFDOCUMENT_H
5#define QPDFDOCUMENT_H
6
7#include <QtPdf/qtpdfglobal.h>
8
9#include <QtCore/qobject.h>
10#include <QtCore/QAbstractListModel>
11#include <QtGui/qimage.h>
12#include <QtPdf/qpdfdocumentrenderoptions.h>
13#include <QtPdf/qpdfselection.h>
14
16
17class QPdfDocumentPrivate;
18class QNetworkReply;
19
20class Q_PDF_EXPORT QPdfDocument : public QObject
21{
22 Q_OBJECT
23
24 Q_PROPERTY(int pageCount READ pageCount NOTIFY pageCountChanged FINAL)
25 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged FINAL)
26 Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
27 Q_PROPERTY(QAbstractListModel* pageModel READ pageModel NOTIFY pageModelChanged FINAL)
28
29public:
30 enum class Status {
31 Null,
32 Loading,
33 Ready,
34 Unloading,
35 Error
36 };
37 Q_ENUM(Status)
38
39 enum class Error {
40 None,
41 Unknown,
42 DataNotYetAvailable,
43 FileNotFound,
44 InvalidFileFormat,
45 IncorrectPassword,
46 UnsupportedSecurityScheme
47 };
48 Q_ENUM(Error)
49
50 enum class MetaDataField {
51 Title,
52 Subject,
53 Author,
54 Keywords,
55 Producer,
56 Creator,
57 CreationDate,
58 ModificationDate
59 };
60 Q_ENUM(MetaDataField)
61
62 enum class PageModelRole {
63 Label = Qt::UserRole,
64 PointSize,
65 NRoles
66 };
67 Q_ENUM(PageModelRole)
68
69 QPdfDocument() : QPdfDocument(nullptr) {}
70 explicit QPdfDocument(QObject *parent);
71 ~QPdfDocument() override;
72
73 Error load(const QString &fileName);
74
75 Status status() const;
76
77 void load(QIODevice *device);
78 void setPassword(const QString &password);
79 QString password() const;
80
81 QVariant metaData(MetaDataField field) const;
82
83 Error error() const;
84
85 void close();
86
87 int pageCount() const;
88
89 Q_INVOKABLE QSizeF pagePointSize(int page) const;
90
91 Q_INVOKABLE QString pageLabel(int page);
92 Q_INVOKABLE int pageIndexForLabel(const QString &label);
93
94 QAbstractListModel *pageModel();
95
96 QImage render(int page, QSize imageSize, QPdfDocumentRenderOptions options = QPdfDocumentRenderOptions());
97
98 Q_INVOKABLE QPdfSelection getSelection(int page, QPointF start, QPointF end);
99 Q_INVOKABLE QPdfSelection getSelectionAtIndex(int page, int startIndex, int maxLength);
100 Q_INVOKABLE QPdfSelection getAllText(int page);
101
102Q_SIGNALS:
103 void passwordChanged();
104 void passwordRequired();
105 void statusChanged(QPdfDocument::Status status);
106 void pageCountChanged(int pageCount);
107 void pageModelChanged();
108
109private:
110 friend struct QPdfBookmarkModelPrivate;
111 friend class QPdfFile;
112 friend class QPdfLinkModelPrivate;
113 friend class QPdfPageModel;
114 friend class QPdfSearchModel;
115 friend class QPdfSearchModelPrivate;
116 friend class QQuickPdfSelection;
117
118 QString fileName() const;
119
120 Q_PRIVATE_SLOT(d, void _q_tryLoadingWithSizeFromContentHeader())
121 Q_PRIVATE_SLOT(d, void _q_copyFromSequentialSourceDevice())
122 QScopedPointer<QPdfDocumentPrivate> d;
123};
124
125QT_END_NAMESPACE
126
127#endif // QPDFDOCUMENT_H
The QPdfBookmarkModel class holds a tree of of links (anchors) within a PDF document,...
The QPdfDocument class loads a PDF document and renders pages from it.
Combined button and popup list for selecting options.
QHash< int, QByteArray > m_roleNames
QPointer< QPdfDocument > m_document
void appendChildNode(BookmarkNode *parentBookmarkNode, FPDF_BOOKMARK parentBookmark, int level, FPDF_DOCUMENT document)
QScopedPointer< BookmarkNode > m_rootNode