QPdfDocument#

The QPdfDocument class loads a PDF document and renders pages from it. More

Inheritance diagram of PySide6.QtPdf.QPdfDocument

Synopsis#

Properties#

Functions#

Signals#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

class PySide6.QtPdf.QPdfDocument#

PySide6.QtPdf.QPdfDocument(parent)

Parameters:

parentPySide6.QtCore.QObject

Constructs a new document with parent object parent.

Note

Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtPdf.QPdfDocument.pageCount: int#

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

Access functions:
property PᅟySide6.QtPdf.QPdfDocument.pageModel: PySide6.QtCore.QAbstractListModel#

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

See also

PageModelRole

Access functions:
property PᅟySide6.QtPdf.QPdfDocument.password: str#

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:
property PᅟySide6.QtPdf.QPdfDocument.status: Status#

This property holds the current status of the document.

Access functions:
PySide6.QtPdf.QPdfDocument.Status#

This enum describes the current status of the document.

Constant

Description

QPdfDocument.Status.Null

The initial status after the document has been created or after it has been closed.

QPdfDocument.Status.Loading

The status after load() has been called and before the document is fully loaded.

QPdfDocument.Status.Ready

The status when the document is fully loaded and its data can be accessed.

QPdfDocument.Status.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.

QPdfDocument.Status.Error

The status after Loading, if loading has failed.

See also

status()

PySide6.QtPdf.QPdfDocument.Error#

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

Constant

Description

QPdfDocument.Error.None

No error occurred.

QPdfDocument.Error.Unknown

Unknown type of error.

QPdfDocument.Error.DataNotYetAvailable

The document is still loading, it’s too early to attempt the operation.

QPdfDocument.Error.FileNotFound

The file given to load() was not found.

QPdfDocument.Error.InvalidFileFormat

The file given to load() is not a valid PDF file.

QPdfDocument.Error.IncorrectPassword

The password given to setPassword() is not correct for this file.

QPdfDocument.Error.UnsupportedSecurityScheme

QPdfDocument is not able to unlock this kind of PDF file.

See also

error()

PySide6.QtPdf.QPdfDocument.MetaDataField#

This enum describes the available fields of meta data.

Constant

Description

QPdfDocument.MetaDataField.Title

The document’s title as QString.

QPdfDocument.MetaDataField.Author

The name of the person who created the document as QString.

QPdfDocument.MetaDataField.Subject

The subject of the document as QString.

QPdfDocument.MetaDataField.Keywords

Keywords associated with the document as QString.

QPdfDocument.MetaDataField.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.

QPdfDocument.MetaDataField.Producer

If the document was converted to PDF from another format, the name of the conforming product that converted it to PDF as QString.

QPdfDocument.MetaDataField.CreationDate

The date and time the document was created as QDateTime.

QPdfDocument.MetaDataField.ModificationDate

The date and time the document was most recently modified as QDateTime.

See also

metaData()

PySide6.QtPdf.QPdfDocument.PageModelRole#

Roles in pageModel() .

Constant

Description

QPdfDocument.PageModelRole.Label

The page number to be used for display purposes (QString).

QPdfDocument.PageModelRole.PointSize

The page size in points (1/72 of an inch) (QSizeF).

PySide6.QtPdf.QPdfDocument.close()#

Closes the document.

PySide6.QtPdf.QPdfDocument.error()#
Return type:

Error

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

PySide6.QtPdf.QPdfDocument.getAllText(page)#
Parameters:

page – int

Return type:

PySide6.QtPdf.QPdfSelection

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

PySide6.QtPdf.QPdfDocument.getSelection(page, start, end)#
Parameters:
Return type:

PySide6.QtPdf.QPdfSelection

Returns information about the text on the given page that can be found between the given start and end points, if any.

PySide6.QtPdf.QPdfDocument.getSelectionAtIndex(page, startIndex, maxLength)#
Parameters:
  • page – int

  • startIndex – int

  • maxLength – int

Return type:

PySide6.QtPdf.QPdfSelection

Returns information about the text on the given page that can be found beginning at the given startIndex with at most maxLength characters.

PySide6.QtPdf.QPdfDocument.load(device)#
Parameters:

devicePySide6.QtCore.QIODevice

Loads the document contents from device.

PySide6.QtPdf.QPdfDocument.load(fileName)
Parameters:

fileName – str

Return type:

Error

Loads the document contents from fileName.

PySide6.QtPdf.QPdfDocument.metaData(field)#
Parameters:

fieldMetaDataField

Return type:

object

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

PySide6.QtPdf.QPdfDocument.pageCount()#
Return type:

int

Getter of property pageCount .

PySide6.QtPdf.QPdfDocument.pageCountChanged(pageCount)#
Parameters:

pageCount – int

Notification signal of property pageCount .

PySide6.QtPdf.QPdfDocument.pageIndexForLabel(label)#
Parameters:

label – str

Return type:

int

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

See also

pageLabel()

PySide6.QtPdf.QPdfDocument.pageLabel(page)#
Parameters:

page – int

Return type:

str

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.

PySide6.QtPdf.QPdfDocument.pageModel()#
Return type:

PySide6.QtCore.QAbstractListModel

Getter of property pageModel .

PySide6.QtPdf.QPdfDocument.pageModelChanged()#

Notification signal of property pageModel .

PySide6.QtPdf.QPdfDocument.pagePointSize(page)#
Parameters:

page – int

Return type:

PySide6.QtCore.QSizeF

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

PySide6.QtPdf.QPdfDocument.password()#
Return type:

str

See also

setPassword()

Getter of property password .

PySide6.QtPdf.QPdfDocument.passwordChanged()#

Notification signal of property password .

PySide6.QtPdf.QPdfDocument.passwordRequired()#
PySide6.QtPdf.QPdfDocument.render(page, imageSize[, options=QPdfDocumentRenderOptions()])#
Parameters:
Return type:

PySide6.QtGui.QImage

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.

PySide6.QtPdf.QPdfDocument.setPassword(password)#
Parameters:

password – str

See also

password()

Setter of property password .

PySide6.QtPdf.QPdfDocument.status()#
Return type:

Status

Getter of property status .

PySide6.QtPdf.QPdfDocument.statusChanged(status)#
Parameters:

statusStatus

Notification signal of property status .