org.apache.pdfbox.pdmodel.common

## Class PDMetadata

- java.lang.Object
- - org.apache.pdfbox.pdmodel.common.PDStream
  - - org.apache.pdfbox.pdmodel.common.PDMetadata

All Implemented Interfaces:
  COSObjectable

    public class PDMetadata
    extends PDStream

This class represents metadata for various objects in a PDF document.

Author:
  Ben Litchfield

### Constructor Summary

Constructors
Constructor and Description
`PDMetadata(COSStream str)` Constructor.
`PDMetadata(PDDocument document)` This will create a new PDMetadata object with the /Type and /Subtype entries for a document level metadata object.
`PDMetadata(PDDocument doc, InputStream str)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`InputStream` `exportXMPMetadata()` Extract the XMP metadata.
`void` `importXMPMetadata(byte[] xmp)` Import an XMP stream into the PDF document.

### Methods inherited from class org.apache.pdfbox.pdmodel.common.PDStream

`createInputStream, createInputStream, createInputStream, createOutputStream, createOutputStream, getCOSObject, getDecodedStreamLength, getDecodeParms, getFile, getFileDecodeParams, getFileFilters, getFilters, getLength, getMetadata, setDecodedStreamLength, setDecodeParms, setFile, setFileDecodeParams, setFileFilters, setFilters, setMetadata, toByteArray`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PDMetadata

    public PDMetadata(PDDocument document)

This will create a new PDMetadata object with the /Type and /Subtype entries for a document level metadata object.

Parameters:
  `document` - The document that the stream will be part of.

#### PDMetadata

    public PDMetadata(PDDocument doc,
                      InputStream str)
               throws IOException

Constructor. Reads all data from the input stream and embeds it into the document, this will close the InputStream. The /Type and /Subtype entries for a document level metadata object will be created.

Parameters:
  `doc` - The document that will hold the stream.
  `str` - The stream parameter.
Throws:
  `IOException` - If there is an error creating the stream in the document.

#### PDMetadata

    public PDMetadata(COSStream str)

Constructor. This will not set up the /Type and /Subtype entries.

Parameters:
  `str` - The stream parameter.

### Method Detail

#### exportXMPMetadata

    public InputStream exportXMPMetadata()
                                  throws IOException

Extract the XMP metadata. To persist changes back to the PDF you must call importXMPMetadata.

Returns:
  A stream to get the xmp data from.
Throws:
  `IOException` - If there is an error parsing the XMP data.

#### importXMPMetadata

    public void importXMPMetadata(byte[] xmp)
                           throws IOException

Import an XMP stream into the PDF document.

Parameters:
  `xmp` - The XMP data.
Throws:
  `IOException` - If there is an error generating the XML document.