pdftools_sdk.pdf_a.conversion.converter

Module Attributes

ConversionEventFunc

The event for errors, warnings, and informational messages that occur during conversion

Classes

Converter()

The class to convert PDF documents to PDF/A

pdftools_sdk.pdf_a.conversion.converter.ConversionEventFunc

The event for errors, warnings, and informational messages that occur during conversion

Report a conversion event that occurred in pdftools_sdk.pdf_a.conversion.converter.Converter.convert() . These events can be used to:

  • Generate a detailed conversion report.

  • Detect and handle critical conversion events.

Note that if a document cannot be converted to the requested conformance, the pdftools_sdk.pdf_a.conversion.converter.Converter.convert() throws an exception. However, even if the output document meets all required standards, the conversion might have resulted in differences that might be acceptable in some processes but not in others. Such potentially critical conversion issues are reported as conversion events.

We suggest checking which conversion events can be tolerated in your conversion process and which must be considered critical:

Parameters:

alias of Callable[[str | None, str, EventSeverity, EventCategory, EventCode, str, int], None]

class pdftools_sdk.pdf_a.conversion.converter.Converter[source]

Bases: _NativeObject

The class to convert PDF documents to PDF/A

__init__()[source]
add_invoice_xml(invoice_type: InvoiceType, invoice: IOBase, af_relationship: AFRelationship | None = None) None[source]

Prepares the invoice XML file (ZUGFeRD or Factur-X) for embedding.

Note: This requires the compliance to be set to PDF/A-3.

Parameters:
Raises:

ValueError – The invoice stream could not be opened for reading.

add_associated_file(embedded_file: IOBase, name: str, associate: int | None = None, af_relationship: AFRelationship | None = None, mime_type: str | None = None, description: str | None = None, modification_date: datetime | None = None) None[source]

Prepares the associated file for embedding.

Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.

Parameters:
  • embeddedFile (io.IOBase) – The stream of the embedded file.

  • name (str) – The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.

  • associate (Optional[int]) – The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If None, the default value is 0 for PDF/A-3 and -1 otherwise.

  • afRelationship (Optional[pdftools_sdk.pdf_a.conversion.a_f_relationship.AFRelationship]) – The relationship of the embedded file to the object associate. (Ignored, if associate is -1.) If None, the default value is pdftools_sdk.pdf_a.conversion.a_f_relationship.AFRelationship.UNSPECIFIED .

  • mimeType (Optional[str]) – MIME ­Type of the embedded file. Common values other than the default are “application/pdf”, “application/xml” or “application/msword”. If None, the default value is “application/octet-stream”.

  • description (Optional[str]) – A description of the embedded file. This is presented to the user when viewing the list of embedded files. If None, the default value is “”.

  • modificationDate (Optional[datetime]) – The modify date of the file. If None, the default value is modification date of the file on the file system or current time, if not available.

Raises:
  • ValueError – The associated file stream could not be opened for reading.

  • ValueError – The associate argument is invalid.

  • OSError – Error reading from embeddedFile.

convert(analysis: AnalysisResult, document: Document, out_stream: IOBase, options: ConversionOptions | None = None, out_options: OutputOptions | None = None) Document[source]

Convert a document to PDF/A.

Note that it is highly recommended to use pdftools_sdk.pdf_a.conversion.converter.ConversionEventFunc() to detect critical conversion events.

Parameters:
Returns:

The result of the conversion

Return type:

pdftools_sdk.pdf.document.Document

Raises:
add_conversion_event_handler(handler: Callable[[str | None, str, EventSeverity, EventCategory, EventCode, str, int], None]) None[source]

Add handler for the ConversionEventFunc() event.

Parameters:

handler – Event handler. If a handler is added that is already registered, it is ignored.

remove_conversion_event_handler(handler: Callable[[str | None, str, EventSeverity, EventCategory, EventCode, str, int], None]) None[source]

Remove registered handler of the ConversionEventFunc() event.

Parameters:

handler – Event handler that shall be removed. If a handler is not registered, it is ignored.