QPdfDocument Class | Qt PDF 6.7.1 (2024)

Member Type Documentation

enum class QPdfDocument::Error

This enum describes the error while attempting the last operation on the document.

ConstantValueDescription
QPdfDocument::Error::None0No error occurred.
QPdfDocument::Error::Unknown1Unknown type of error.
QPdfDocument::Error::DataNotYetAvailable2The document is still loading, it's too early to attempt the operation.
QPdfDocument::Error::FileNotFound3The file given to load() was not found.
QPdfDocument::Error::InvalidFileFormat4The file given to load() is not a valid PDF file.
QPdfDocument::Error::IncorrectPassword5The password given to setPassword() is not correct for this file.
QPdfDocument::Error::UnsupportedSecurityScheme6QPdfDocument is not able to unlock this kind of PDF file.

See also QPdfDocument::error().

enum class QPdfDocument::MetaDataField

This enum describes the available fields of meta data.

ConstantValueDescription
QPdfDocument::MetaDataField::Title0The document's title as QString.
QPdfDocument::MetaDataField::Author2The name of the person who created the document as QString.
QPdfDocument::MetaDataField::Subject1The subject of the document as QString.
QPdfDocument::MetaDataField::Keywords3Keywords associated with the document as QString.
QPdfDocument::MetaDataField::Creator5If 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.
QPdfDocument::MetaDataField::Producer4If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF as QString.
QPdfDocument::MetaDataField::CreationDate6The date and time the document was created as QDateTime.
QPdfDocument::MetaDataField::ModificationDate7The date and time the document was most recently modified as QDateTime.

See also QPdfDocument::metaData().

enum class QPdfDocument::PageModelRole

Roles in pageModel().

ConstantValueDescription
QPdfDocument::PageModelRole::LabelQt::UserRoleThe page number to be used for display purposes (QString).
QPdfDocument::PageModelRole::PointSize257The page size in points (1/72 of an inch) (QSizeF).

enum class QPdfDocument::Status

This enum describes the current status of the document.

ConstantValueDescription
QPdfDocument::Status::Null0The initial status after the document has been created or after it has been closed.
QPdfDocument::Status::Loading1The status after load() has been called and before the document is fully loaded.
QPdfDocument::Status::Ready2The status when the document is fully loaded and its data can be accessed.
QPdfDocument::Status::Unloading3The 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.
QPdfDocument::Status::Error4The status after Loading, if loading has failed.

See also QPdfDocument::status().

Property Documentation

[read-only] pageCount : const int

This property holds the number of pages in the loaded document or 0 if no document is loaded.

Access functions:

Notifier signal:

void pageCountChanged(int pageCount)

[read-only] pageModel : QAbstractListModel* const

This property holds an instance of QAbstractListModel to provide page-specific metadata, containing one row for each page in the document.

Access functions:

QAbstractListModel *pageModel()

Notifier signal:

void pageModelChanged()

See also QPdfDocument::PageModelRole.

password : QString

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.

Access functions:

QString password() const
void setPassword(const QString &password)

Notifier signal:

void passwordChanged()

[read-only] status : const Status

This property holds the current status of the document.

Access functions:

QPdfDocument::Status status() const

Notifier signal:

void statusChanged(QPdfDocument::Status status)

Member Function Documentation

[explicit] QPdfDocument::QPdfDocument(QObject *parent)

Constructs a new document with parent object parent.

[override virtual noexcept] QPdfDocument::~QPdfDocument()

Destroys the document.

void QPdfDocument::close()

Closes the document.

QPdfDocument::Error QPdfDocument::error() const

Returns the type of error if status is Error, or NoError if there is no error.

[invokable] QPdfSelection QPdfDocument::getAllText(int page)

Returns all the text and its bounds on the given page.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[invokable] 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.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[invokable] 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.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QPdfDocument::Error QPdfDocument::load(const QString &fileName)

Loads the document contents from fileName.

void QPdfDocument::load(QIODevice *device)

Loads the document contents from device.

QVariant QPdfDocument::metaData(QPdfDocument::MetaDataField field) const

Returns the meta data of the document for the given field.

[invokable, since 6.6] int QPdfDocument::pageIndexForLabel(const QString &label)

Returns the index of the page that has the label, or -1 if not found.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

This function was introduced in Qt 6.6.

See also pageLabel().

[invokable] 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.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also pageIndexForLabel().

[invokable] QSizeF QPdfDocument::pagePointSize(int page) const

Returns the size of page page in points (1/72 of an inch).

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

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.

QPdfDocument Class | Qt PDF 6.7.1 (2024)
Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 6532

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.