Class Metadata


  • public class Metadata
    extends 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.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Metadata copy​(Document targetDocument, Metadata metadata)
      Copy a metadata object
      static Metadata create​(Document targetDocument, Stream xmp)
      Create a new metadata object
      java.lang.String getAuthor()
      The name of the person who created the document or resource.
      java.time.OffsetDateTime getCreationDate()
      The date and time the document or resource was originally created.
      java.lang.String getCreator()
      The original application that created the document.
      StringMap getCustomEntries()
      The custom entries in the document information dictionary (Getter)
      java.lang.String getKeywords()
      Keywords associated with the document or resource.
      java.time.OffsetDateTime getModificationDate()
      The date and time the document or resource was most recently modified.
      java.lang.String getProducer()
      The application that created the PDF (Getter)
      java.lang.String getSubject()
      The subject of the document or resource.
      java.lang.String getTitle()
      The title of the document or resource.
      Stream getXmp()
      The XMP metadata (Getter)
      void setAuthor​(java.lang.String value)
      The name of the person who created the document or resource.
      void setCreationDate​(java.time.OffsetDateTime value)
      The date and time the document or resource was originally created.
      void setCreator​(java.lang.String value)
      The original application that created the document.
      void setKeywords​(java.lang.String value)
      Keywords associated with the document or resource.
      void setSubject​(java.lang.String value)
      The subject of the document or resource.
      void setTitle​(java.lang.String value)
      The title of the document or resource.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static Metadata create​(Document targetDocument,
                                      Stream xmp)
                               throws java.io.IOException,
                                      CorruptException

        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 Document.setMetadata(com.pdftools.toolbox.pdf.Metadata) or as page metadata using Page.setMetadata(com.pdftools.toolbox.pdf.Metadata).
        Parameters:
        targetDocument - the output document with which the returned object is associated
        xmp - A stream containing an XMP file or null to create an empty metadata object.
        Returns:
        the newly created metadata object
        Throws:
        java.lang.IllegalArgumentException - if the targetDocument argument has already been closed
        java.lang.IllegalArgumentException - if the targetDocument argument is read-only
        java.io.IOException - if the xmp stream could not be read
        CorruptException - if the xmp stream is corrupt
        java.lang.IllegalArgumentException - if targetDocument is null
        java.lang.IllegalArgumentException - if xmp is null
      • copy

        public static Metadata copy​(Document targetDocument,
                                    Metadata metadata)
                             throws java.io.IOException,
                                    CorruptException,
                                    ConformanceException

        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 Document.setMetadata(com.pdftools.toolbox.pdf.Metadata) or as page metadata using Page.setMetadata(com.pdftools.toolbox.pdf.Metadata).
        Parameters:
        targetDocument - the output document with which the returned object is associated
        metadata - the metadata of a different document
        Returns:
        a metadata object with the same content, but associated with the current document.
        Throws:
        java.io.IOException - Error reading from the source document or writing to the target document
        CorruptException - The source document is corrupt
        ConformanceException - The conformance level of the source document is not compatible with the conformance level of the target document.
        java.lang.IllegalArgumentException - if the targetDocument argument has already been closed
        java.lang.IllegalArgumentException - if the targetDocument argument is read-only
        java.lang.IllegalArgumentException - if the metadata object has already been closed
        java.lang.IllegalArgumentException - if the metadata object is not associated with an input document
        java.lang.IllegalArgumentException - if targetDocument is null
        java.lang.IllegalArgumentException - if metadata is null
      • getTitle

        public java.lang.String getTitle()

        The title of the document or resource. (Getter)

        This property corresponds to the "dc:title" entry in the XMP metadata and to the "Title" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setTitle

        public void setTitle​(java.lang.String value)

        The title of the document or resource. (Setter)

        This property corresponds to the "dc:title" entry in the XMP metadata and to the "Title" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getAuthor

        public java.lang.String getAuthor()

        The name of the person who created the document or resource. (Getter)

        This property corresponds to the "dc:creator" entry in the XMP metadata and to the "Author" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setAuthor

        public void setAuthor​(java.lang.String value)

        The name of the person who created the document or resource. (Setter)

        This property corresponds to the "dc:creator" entry in the XMP metadata and to the "Author" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getSubject

        public java.lang.String getSubject()

        The subject of the document or resource. (Getter)

        This property corresponds to the "dc:description" entry in the XMP metadata and to the "Subject" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setSubject

        public void setSubject​(java.lang.String value)

        The subject of the document or resource. (Setter)

        This property corresponds to the "dc:description" entry in the XMP metadata and to the "Subject" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getKeywords

        public java.lang.String getKeywords()

        Keywords associated with the document or resource. (Getter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setKeywords

        public void setKeywords​(java.lang.String value)

        Keywords associated with the document or resource. (Setter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getCreator

        public java.lang.String getCreator()

        The original application that created the document. (Getter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setCreator

        public void setCreator​(java.lang.String value)

        The original application that created the document. (Setter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getProducer

        public java.lang.String getProducer()

        The application that created the PDF (Getter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • getCreationDate

        public java.time.OffsetDateTime getCreationDate()

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

        This property corresponds to the "xmp:CreateDate" entry in the XMP metadata and to the "CreationDate" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • setCreationDate

        public void setCreationDate​(java.time.OffsetDateTime value)

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

        This property corresponds to the "xmp:CreateDate" entry in the XMP metadata and to the "CreationDate" entry in the document information dictionary.
        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
        java.lang.UnsupportedOperationException - the document is read-only
      • getModificationDate

        public java.time.OffsetDateTime getModificationDate()
                                                     throws CorruptException

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

        This property corresponds to the "xmp:ModifyDate" entry in the XMP metadata and to the "ModDate" entry in the document information dictionary.
        Throws:
        CorruptException - The date is corrupt.
        java.lang.IllegalStateException - if the metadata have already been closed
      • getXmp

        public Stream getXmp()

        The XMP metadata (Getter)

        The XMP metadata stream or null if there is none.

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

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed
      • getCustomEntries

        public StringMap getCustomEntries()

        The custom entries in the document information dictionary (Getter)

        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.

        Throws:
        java.lang.IllegalStateException - if the metadata have already been closed