![]() |
Qt 6.x
The Qt SDK
|
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 () |
![]() | |
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 (QAnyStringView 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. | |
![]() | |
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 | 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. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
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::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), 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 (const QString &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 > | |
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. | |
![]() | |
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 | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
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) |
![]() | |
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) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
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 519 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::q.
|
override |
Destroys the document.
Definition at line 529 of file qpdfdocument.cpp.
void QPdfDocument::close | ( | ) |
Closes the document.
Definition at line 731 of file qpdfdocument.cpp.
References QByteArray::clear(), QPdfDocumentPrivate::clear(), QPdfDocumentPrivate::doc, emit, QByteArray::isEmpty(), Null, QPdfDocumentPrivate::password, passwordChanged(), QPdfDocumentPrivate::setStatus(), and Unloading.
Referenced by load(), and load().
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 723 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::lastError.
Referenced by QQuickPdfDocument::classBegin(), and QQuickPdfDocument::error().
QPdfSelection QPdfDocument::getAllText | ( | int | page | ) |
Returns all the text and its bounds on the given page.
Definition at line 1028 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::doc, QPdfDocumentPrivate::getText(), i, QRectF::isNull(), lock, page, qCDebug, rect, text, and QRectF::united().
Referenced by QQuickPdfSelection::selectAll().
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 930 of file qpdfdocument.cpp.
References CharacterHitTolerance, QPdfDocumentPrivate::doc, QPdfDocumentPrivate::getCharBox(), QPdfDocumentPrivate::getText(), i, QRectF::isNull(), lock, page, qAbs(), qCDebug, qSwap(), rect, QRectF::right(), text, QRectF::united(), and QRectF::x().
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 984 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::doc, QPdfDocumentPrivate::getCharPosition(), QPdfDocumentPrivate::getText(), i, QList< T >::isEmpty(), QRectF::isNull(), lock, page, pageCount, qCDebug, rect, QString::size(), text, and QRectF::united().
QPdfDocument::Error QPdfDocument::load | ( | const QString & | fileName | ) |
Loads the document contents from fileName.
Definition at line 536 of file qpdfdocument.cpp.
References close(), Error, fileName, FileNotFound, QPdfDocumentPrivate::lastError, QPdfDocumentPrivate::load(), Loading, qCDebug, QIODeviceBase::ReadOnly, and QPdfDocumentPrivate::setStatus().
Referenced by QQuickPdfDocument::classBegin(), and QQuickPdfDocument::setSource().
Loads the document contents from device.
Definition at line 594 of file qpdfdocument.cpp.
References close(), device, QPdfDocumentPrivate::load(), Loading, and QPdfDocumentPrivate::setStatus().
QVariant QPdfDocument::metaData | ( | MetaDataField | field | ) | const |
Returns the meta data of the document for the given field.
Definition at line 650 of file qpdfdocument.cpp.
References Author, QString::chop(), QByteArray::constData(), CreationDate, Creator, QPdfDocumentPrivate::doc, QString::endsWith(), QString::fromUtf16(), QString::insert(), Qt::ISODate, Keywords, lock, metaObject(), QString::mid(), ModificationDate, Producer, QString::replace(), QString::startsWith(), Subject, text, Title, and QMetaEnum::valueToKey().
Referenced by QPdfIOHandler::option().
int QPdfDocument::pageCount | ( | ) | const |
Definition at line 754 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::pageCount.
|
signal |
int QPdfDocument::pageIndexForLabel | ( | QAnyStringView | label | ) |
Returns the index of the page that has the label, or -1
if not found.
Definition at line 832 of file qpdfdocument.cpp.
References i, QPdfDocumentPrivate::pageCount, pageLabel(), and QByteArrayView::trimmed().
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 815 of file qpdfdocument.cpp.
References QByteArray::data(), QPdfDocumentPrivate::doc, QString::fromUtf16(), lock, QString::number(), and page.
Referenced by pageIndexForLabel().
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 762 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::checkPageComplete(), QPdfDocumentPrivate::doc, lock, and page.
Referenced by QPdfIOHandler::currentImageRect(), QPdfIOHandler::option(), QPdfIOHandler::read(), and render().
QString QPdfDocument::password | ( | ) | const |
Definition at line 622 of file qpdfdocument.cpp.
References QString::fromUtf8(), and QPdfDocumentPrivate::password.
|
signal |
Referenced by QQuickPdfDocument::classBegin(), close(), and setPassword().
|
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 852 of file qpdfdocument.cpp.
References QPdfDocumentRenderOptions::Annotations, QRect::bottom(), QPdfDocumentPrivate::checkPageComplete(), QPdfDocumentPrivate::doc, QPdfDocumentRenderOptions::ForceHalftone, QImage::Format_ARGB32, QPdfDocumentRenderOptions::Grayscale, QSize::height(), QSizeF::height(), QPdfDocumentRenderOptions::ImageAliased, QSize::isNull(), QRect::isValid(), QRect::left(), lock, QPdfDocumentRenderOptions::OptimizedForLcd, page, pagePointSize(), QPdfDocumentRenderOptions::PathAliased, Q_UNLIKELY, qCDebug, QPdfDocumentRenderOptions::renderFlags(), QRect::right(), QPdfDocumentRenderOptions::rotation(), QPdfDocumentRenderOptions::scaledClipRect(), QPdfDocumentRenderOptions::scaledSize(), QTimer::start(), QPdfDocumentRenderOptions::TextAliased, timer, QPdfDocumentPrivate::toFPDFRotation(), QRect::top(), Qt::transparent, QSize::width(), QSizeF::width(), QVector2D::x(), and QVector2D::y().
Referenced by QPdfIOHandler::read(), and RenderWorker::requestPage().
Definition at line 611 of file qpdfdocument.cpp.
References emit, password, QPdfDocumentPrivate::password, passwordChanged(), and QString::toUtf8().
QPdfDocument::Status QPdfDocument::status | ( | ) | const |
Definition at line 586 of file qpdfdocument.cpp.
References QPdfDocumentPrivate::status.
|
signal |
Referenced by QPdfPageModel::QPdfPageModel(), QQuickPdfDocument::classBegin(), QPdfLinkModel::setDocument(), QPdfPageSelector::setDocument(), and QQuickPdfPageImage::setDocument().
|
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 125 of file qpdfdocument.h.
Referenced by QPdfSearchModelPrivate::clearResults(), QPdfPageSelectorPrivate::documentStatusChanged(), getSelectionAtIndex(), QPdfIOHandler::imageCount(), QPdfSearchModelPrivate::pageAndIndexForResult(), QPdfIOHandler::read(), and QQuickPdfSearchModel::setCurrentPage().
|
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 125 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 125 of file qpdfdocument.h.
Referenced by setPassword().
|
read |
This property holds the current status of the document.
Definition at line 125 of file qpdfdocument.h.
Referenced by QPdfPageSelectorPrivate::documentStatusChanged(), QPdfBookmarkModelPrivate::rebuild(), QPdfPageRenderer::requestPage(), RenderWorker::requestPage(), and QQuickPdfPageImage::setDocument().