pdftools_toolbox.pdf.metadata

Classes

Metadata(handle)

Represents the metadata of a document or an object in a document.

class pdftools_toolbox.pdf.metadata.Metadata(handle)[source]

Bases: _NativeObject

Represents the metadata of a document or an object in a document.

For document level metadata, all changes are reflected in both, XMP metadata and document info dictionary depending on the conformance of the document.

static create(target_document: Document, xmp: IOBase) Metadata[source]

Create a new metadata object

The newly created metadata object is associated with the target document but not (yet) used as the document metadata. The object can be used either as document metadata using pdftools_toolbox.pdf.document.Document.metadata or as page metadata using pdftools_toolbox.pdf.page.Page.metadata .

Parameters:
  • targetDocument (pdftools_toolbox.pdf.document.Document) – the output document with which the returned object is associated

  • xmp (io.IOBase) – A stream containing an XMP file or None to create an empty metadata object.

Returns:

the newly created metadata object

Return type:

pdftools_toolbox.pdf.metadata.Metadata

Raises:
  • ValueError – if the targetDocument argument has already been closed

  • ValueError – if the targetDocument argument is read-only

  • OSError – if the xmp stream could not be read

  • pdftools_toolbox.corrupt_error.CorruptError – if the xmp stream is corrupt

static copy(target_document: Document, metadata: Metadata) Metadata[source]

Copy a metadata object

Copy a metadata object from an input document to the given targetDocument. The returned object is associated with the target document but not (yet) used as the document metadata. The object can be used either as document metadata using pdftools_toolbox.pdf.document.Document.metadata or as page metadata using pdftools_toolbox.pdf.page.Page.metadata .

Parameters:
Returns:

a metadata object with the same content, but associated with the current document.

Return type:

pdftools_toolbox.pdf.metadata.Metadata

Raises:
  • OSError – Error reading from the source document or writing to the target document

  • pdftools_toolbox.corrupt_error.CorruptError – The source document is corrupt

  • pdftools_toolbox.conformance_error.ConformanceError – The conformance level of the source document is not compatible with the conformance level of the target document.

  • ValueError – if the targetDocument argument has already been closed

  • ValueError – if the targetDocument argument is read-only

  • ValueError – if the metadata object has already been closed

  • ValueError – if the metadata object is not associated with an input document

property title: str | None

The title of the document or resource.

This property corresponds to the “dc:title” entry in the XMP metadata and to the “Title” entry in the document information dictionary.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property author: str | None

The name of the person who created the document or resource.

This property corresponds to the “dc:creator” entry in the XMP metadata and to the “Author” entry in the document information dictionary.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property subject: str | None

The subject of the document or resource.

This property corresponds to the “dc:description” entry in the XMP metadata and to the “Subject” entry in the document information dictionary.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property keywords: str | None

Keywords associated with the document or resource.

Keywords can be separated by:

  • carriage return / line feed

  • comma

  • semicolon

  • tab

  • double space

This property corresponds to the “pdf:Keywords” entry in the XMP metadata and to the “Keywords” entry in the document information dictionary.

Setting this property also sets the XMP property dc:subject accordingly.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property creator: str | None

The original application that created the document.

The name of the first known tool used to create the document or resource.

This property corresponds to the “xmp:CreatorTool” entry in the XMP metadata and to the “Creator” entry in the document information dictionary.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property producer: str | None

The application that created the PDF

If the document was converted to PDF from another format, the name of the PDF processor that converted it to PDF.

This property corresponds to the “pdf:Producer” entry in the XMP metadata and to the “Producer” entry in the document information dictionary.

Returns:

Optional[str]

Raises:

StateError – if the metadata have already been closed

property creation_date: datetime | None

The date and time the document or resource was originally created.

This property corresponds to the “xmp:CreateDate” entry in the XMP metadata and to the “CreationDate” entry in the document information dictionary.

Returns:

Optional[datetime]

Raises:

StateError – if the metadata have already been closed

property modification_date: datetime | None

The date and time the document or resource was most recently modified.

This property corresponds to the “xmp:ModifyDate” entry in the XMP metadata and to the “ModDate” entry in the document information dictionary.

Returns:

Optional[datetime]

Raises:
property xmp: IOBase

The XMP metadata

The XMP metadata stream or None if there is none.

The stream is read-only. To set the XMP stream of a metadata object use the method Document.CreateMetadata instead.

Returns:

io.IOBase

Raises:

StateError – if the metadata have already been closed

property custom_entries: StringMap

The custom entries in the document information dictionary

The standard entries “Title”, “Author”, “Subject”, “Keywords”, “CreationDate”, “ModDate”, “Creator”, “Producer” and “Trapped” are not included in the map. Any attempt to set a standard entry through this map will result in an error. To get or set standard entries use the corresponding properties instead.

Note: The document information dictionary has been superseded by XMP metadata and is deprecated in PDF 2.0.

Returns:

pdftools_toolbox.string_map.StringMap

Raises:

StateError – if the metadata have already been closed