pdftools_sdk.pdf.document

Classes

Document(handle)

The PDF document

class pdftools_sdk.pdf.document.Document(handle)[source]

Bases: _NativeObject

The PDF document

PDF documents are either opened using pdftools_sdk.pdf.document.Document.open() or the result of an operation, e.g. of PDF optimization (see pdftools_sdk.optimization.optimizer.Optimizer.optimize_document() ).

static open(stream: IOBase, password: str | None = None) Document[source]

Open a PDF document.

Documents opened with this method are read-only and cannot be modified.

Parameters:
  • stream (io.IOBase) – The stream from which the PDF is read.

  • password (Optional[str]) – The password to open the PDF document. If None or empty, no password is used.

Returns:

The newly created document instance

Return type:

pdftools_sdk.pdf.document.Document

Raises:
property conformance: Conformance | None

The claimed conformance of the document

This method only returns the claimed conformance level, the document is not validated.

This property can return None if the document’s conformance is unknown.

Returns:

Optional[pdftools_sdk.pdf.conformance.Conformance]

property page_count: int

The number of pages in the document

If the document is a collection (also known as PDF Portfolio), then this property is 0.

Returns:

int

property permissions: Permission | None

The access permissions applicable for this document

This property is None, if the document is not encrypted.

Note that these permissions might be different from the “Document Restrictions Summary” displayed in Adobe Acrobat. This is because Acrobat’s restrictions are also affected by other factors. For example, “Document Assembly” is generally only allowed in Acrobat Pro and not the Acrobat Reader.

Returns:

Optional[pdftools_sdk.pdf.permission.Permission]

property is_linearized: bool

Whether the document is linearized

Returns:

bool

property is_signed: bool

Returns: bool

property signature_fields: SignatureFieldList

Returns: pdftools_sdk.pdf.signature_field_list.SignatureFieldList

property xfa: XfaType

Whether the document is an XML Forms Architecture (XFA) or a PDF document

While XFA documents may seem like regular PDF documents they are not and cannot be processed by many components (error pdftools_sdk.unsupported_feature_error.UnsupportedFeatureError ). An XFA form is included as a resource in a mere shell PDF. The PDF pages’ content is generated dynamically from the XFA data, which is a complex, non-standardized process. For this reason, XFA is forbidden by the ISO Standards ISO 19’005-2 (PDF/A-2) and ISO 32’000-2 (PDF 2.0) and newer. It is recommended to convert XFA documents to PDF using an Adobe product, e.g. by using the “Print to PDF” function of Adobe Acrobat Reader.

Returns:

pdftools_sdk.pdf.xfa_type.XfaType

property metadata: Metadata

The metadata of the document.

Returns:

pdftools_sdk.pdf.metadata.Metadata