![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QPdfDocument class loads a PDF document and renders pages from it. More...
#include <qpdfdocument.h>
Public Types | |
enum class | Status { Null , Loading , Ready , Unloading , Error } |
This enum describes the current status of the document. More... | |
enum class | Error { None , Unknown , DataNotYetAvailable , FileNotFound , InvalidFileFormat , IncorrectPassword , UnsupportedSecurityScheme } |
This enum describes the error while attempting the last operation on the document. More... | |
enum class | MetaDataField { Title , Subject , Author , Keywords , Producer , Creator , CreationDate , ModificationDate } |
This enum describes the available fields of meta data. More... | |
enum class | PageModelRole { Label = Qt::UserRole , PointSize , NRoles } |
Roles in pageModel(). More... |
Signals | |
void | passwordChanged () |
void | passwordRequired () |
void | statusChanged (QPdfDocument::Status status) |
void | pageCountChanged (int pageCount) |
void | pageModelChanged () |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. |
Public Member Functions | |
QPdfDocument () | |
QPdfDocument (QObject *parent) | |
Constructs a new document with parent object parent. | |
~QPdfDocument () override | |
Destroys the document. | |
Error | load (const QString &fileName) |
Loads the document contents from fileName. | |
Status | status () const |
void | load (QIODevice *device) |
Loads the document contents from device. | |
void | setPassword (const QString &password) |
QString | password () const |
QVariant | metaData (MetaDataField field) const |
Returns the meta data of the document for the given field. | |
Error | error () const |
Returns the type of error if \l status is Error , or NoError if there is no error. | |
void | close () |
Closes the document. | |
int | pageCount () const |
Q_INVOKABLE QSizeF | pagePointSize (int page) const |
Returns the size of page page in points (1/72 of an inch). | |
Q_INVOKABLE QString | pageLabel (int page) |
Returns the page number to be used for display purposes. | |
Q_INVOKABLE int | pageIndexForLabel (const QString &label) |
Returns the index of the page that has the label, or -1 if not found. | |
QAbstractListModel * | pageModel () |
QImage | render (int page, QSize imageSize, QPdfDocumentRenderOptions options=QPdfDocumentRenderOptions()) |
Renders the page into a QImage of size imageSize according to the provided renderOptions. | |
Q_INVOKABLE QPdfSelection | getSelection (int page, QPointF start, QPointF end) |
Returns information about the text on the given page that can be found between the given start and end points, if any. | |
Q_INVOKABLE QPdfSelection | getSelectionAtIndex (int page, int startIndex, int maxLength) |
Returns information about the text on the given page that can be found beginning at the given startIndex with at most maxLength characters. | |
Q_INVOKABLE QPdfSelection | getAllText (int page) |
Returns all the text and its bounds on the given page. | |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | isQmlObjectType () const |
Returns whether the object has been created by the QML engine or ownership has been explicitly set via QJSEngine::setObjectOwnership(). | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T> | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T> | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T> | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T> | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . |
Properties | |
int | pageCount |
This property holds the number of pages in the loaded document or 0 if no document is loaded. | |
QString | password |
This property holds the document password. | |
Status | status |
This property holds the current status of the document. | |
QAbstractListModel * | pageModel |
This property holds an instance of QAbstractListModel to provide page-specific metadata, containing one row for each page in the document. | |
Properties inherited from QObject | |
QString | objectName |
the name of this object |
Friends | |
struct | QPdfBookmarkModelPrivate |
class | QPdfFile |
class | QPdfLinkModelPrivate |
class | QPdfPageModel |
class | QPdfSearchModel |
class | QPdfSearchModelPrivate |
class | QQuickPdfSelection |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1, typename Func2> | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1, typename Func2> | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1, typename Func2> | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1> | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) |
The QPdfDocument class loads a PDF document and renders pages from it.
Definition at line 20 of file qpdfdocument.h.
|
strong |
This enum describes the error while attempting the last operation on the document.
\value None No error occurred. \value Unknown Unknown type of error. \value DataNotYetAvailable The document is still loading, it's too early to attempt the operation. \value FileNotFound The file given to load() was not found. \value InvalidFileFormat The file given to load() is not a valid PDF file. \value IncorrectPassword The password given to setPassword() is not correct for this file. \value UnsupportedSecurityScheme QPdfDocument is not able to unlock this kind of PDF file.
Enumerator | |
---|---|
None | |
Unknown | |
DataNotYetAvailable | |
FileNotFound | |
InvalidFileFormat | |
IncorrectPassword | |
UnsupportedSecurityScheme |
Definition at line 39 of file qpdfdocument.h.
|
strong |
This enum describes the available fields of meta data.
\value Title The document's title as QString. \value Author The name of the person who created the document as QString. \value Subject The subject of the document as QString. \value Keywords Keywords associated with the document as QString. \value Creator If the document was converted to PDF from another format, the name of the conforming product that created the original document from which it was converted as QString. \value Producer If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF as QString. \value CreationDate The date and time the document was created as QDateTime. \value ModificationDate The date and time the document was most recently modified as QDateTime.
Enumerator | |
---|---|
Title | |
Subject | |
Author | |
Keywords | |
Producer | |
Creator | |
CreationDate | |
ModificationDate |
Definition at line 50 of file qpdfdocument.h.
|
strong |
Roles in pageModel().
\value Label The page number to be used for display purposes (QString). \value PointSize The page size in points (1/72 of an inch) (QSizeF). \omitvalue NRoles
Enumerator | |
---|---|
Label | |
PointSize | |
NRoles |
Definition at line 62 of file qpdfdocument.h.
|
strong |
This enum describes the current status of the document.
\value Null The initial status after the document has been created or after it has been closed. \value Loading The status after load() has been called and before the document is fully loaded. \value Ready The status when the document is fully loaded and its data can be accessed. \value Unloading The status after close() has been called on an open document. At this point the document is still valid and all its data can be accessed. \value Error The status after Loading, if loading has failed.
Enumerator | |
---|---|
Null | |
Loading | |
Ready | |
Unloading | |
Error |
Definition at line 30 of file qpdfdocument.h.
|
inline |
Definition at line 69 of file qpdfdocument.h.
|
explicit |
Constructs a new document with parent object parent.
Definition at line 570 of file qpdfdocument.cpp.
|
override |
Destroys the document.
Definition at line 580 of file qpdfdocument.cpp.
void QPdfDocument::close | ( | ) |
Closes the document.
Definition at line 782 of file qpdfdocument.cpp.
QPdfDocument::Error QPdfDocument::error | ( | ) | const |
Returns the type of error if \l status is Error
, or NoError
if there is no error.
Definition at line 774 of file qpdfdocument.cpp.
QPdfSelection QPdfDocument::getAllText | ( | int | page | ) |
Returns all the text and its bounds on the given page.
Definition at line 1079 of file qpdfdocument.cpp.
QPdfSelection QPdfDocument::getSelection | ( | int | page, |
QPointF | start, | ||
QPointF | end ) |
Returns information about the text on the given page that can be found between the given start and end points, if any.
Definition at line 981 of file qpdfdocument.cpp.
QPdfSelection QPdfDocument::getSelectionAtIndex | ( | int | page, |
int | startIndex, | ||
int | maxLength ) |
Returns information about the text on the given page that can be found beginning at the given startIndex with at most maxLength characters.
Definition at line 1036 of file qpdfdocument.cpp.
QPdfDocument::Error QPdfDocument::load | ( | const QString & | fileName | ) |
Loads the document contents from fileName.
Definition at line 587 of file qpdfdocument.cpp.
Loads the document contents from device.
Definition at line 645 of file qpdfdocument.cpp.
QVariant QPdfDocument::metaData | ( | MetaDataField | field | ) | const |
Returns the meta data of the document for the given field.
Definition at line 701 of file qpdfdocument.cpp.
int QPdfDocument::pageCount | ( | ) | const |
Definition at line 805 of file qpdfdocument.cpp.
|
signal |
int QPdfDocument::pageIndexForLabel | ( | const QString & | label | ) |
Returns the index of the page that has the label, or -1
if not found.
Definition at line 884 of file qpdfdocument.cpp.
QString QPdfDocument::pageLabel | ( | int | page | ) |
Returns the page number to be used for display purposes.
For example, a document may have multiple sections with different numbering. Perhaps the preface uses roman numerals, the body starts on page 1, and the appendix starts at A1. Whenever a PDF viewer shows a page number, to avoid confusing the user it should be the same "number" as is printed on the corner of the page, rather than the zero-based page index that we use in APIs (assuming the document author has made the page labels match the printed numbers).
If the document does not have custom page numbering, this function returns {page
+ 1}.
Definition at line 866 of file qpdfdocument.cpp.
QAbstractListModel * QPdfDocument::pageModel | ( | ) |
|
signal |
QSizeF QPdfDocument::pagePointSize | ( | int | page | ) | const |
Returns the size of page page in points (1/72 of an inch).
Definition at line 813 of file qpdfdocument.cpp.
QString QPdfDocument::password | ( | ) | const |
Definition at line 673 of file qpdfdocument.cpp.
|
signal |
|
signal |
QImage QPdfDocument::render | ( | int | page, |
QSize | imageSize, | ||
QPdfDocumentRenderOptions | renderOptions = QPdfDocumentRenderOptions() ) |
Renders the page into a QImage of size imageSize according to the provided renderOptions.
Returns the rendered page or an empty image in case of an error.
Note: If the imageSize does not match the aspect ratio of the page in the PDF document, the page is rendered scaled, so that it covers the complete imageSize.
Definition at line 903 of file qpdfdocument.cpp.
Definition at line 662 of file qpdfdocument.cpp.
QPdfDocument::Status QPdfDocument::status | ( | ) | const |
Definition at line 637 of file qpdfdocument.cpp.
|
signal |
|
friend |
Definition at line 110 of file qpdfdocument.h.
|
friend |
Definition at line 111 of file qpdfdocument.h.
|
friend |
Definition at line 112 of file qpdfdocument.h.
|
friend |
Definition at line 113 of file qpdfdocument.h.
|
friend |
Definition at line 114 of file qpdfdocument.h.
|
friend |
Definition at line 115 of file qpdfdocument.h.
|
friend |
Definition at line 116 of file qpdfdocument.h.
|
read |
This property holds the number of pages in the loaded document or 0
if no document is loaded.
Definition at line 24 of file qpdfdocument.h.
|
read |
This property holds an instance of QAbstractListModel to provide page-specific metadata, containing one row for each page in the document.
Definition at line 27 of file qpdfdocument.h.
|
readwrite |
This property holds the document password.
If the document is protected by a password, the user must provide it, and the application must set this property. Otherwise, it's not needed.
Definition at line 25 of file qpdfdocument.h.
|
read |
This property holds the current status of the document.
Definition at line 26 of file qpdfdocument.h.