| <!-- |
| ! Licensed to the Apache Software Foundation (ASF) under one or more |
| ! contributor license agreements. See the NOTICE file distributed with |
| ! this work for additional information regarding copyright ownership. |
| ! The ASF licenses this file to You under the Apache License, Version 2.0 |
| ! (the "License"); you may not use this file except in compliance with |
| ! the License. You may obtain a copy of the License at |
| ! |
| ! http://www.apache.org/licenses/LICENSE-2.0 |
| ! |
| ! Unless required by applicable law or agreed to in writing, software |
| ! distributed under the License is distributed on an "AS IS" BASIS, |
| ! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| ! See the License for the specific language governing permissions and |
| ! limitations under the License. |
| !--> |
| <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd"> |
| <document> |
| <header> |
| <title>PDFBox - PDF Metadata</title> |
| <meta name="keywords">Java PDF Library, XMP, PDF metadata, pdfbox</meta> |
| </header> |
| <body> |
| <section> |
| <title>Accessing Metadata</title> |
| <p> |
| See class:<a href="../javadoc/org/pdfbox/pdmodel/common/PDMetadata.html">org.pdfbox.pdmodel.common.PDMetadata</a> <br/> |
| See example:<a href="../javadoc/org/pdfbox/examples/pdmodel/AddMetadataFromDocInfo.html">AddMetadataFromDocInfo</a> <br/> |
| See Adobe Documentation:<a href="http://partners.adobe.com/public/developer/en/xmp/sdk/xmpspecification.pdf">XMP Specification</a> |
| </p> |
| <p> |
| PDF documents can have XML metadata associated with certain objects within a PDF document. For example, the following PD Model objects |
| have the ability to contain metadata: |
| </p> |
| <ul> |
| <li>PDDocumentCatalog</li> |
| <li>PDPage</li> |
| <li>PDXObject</li> |
| <li>PDICCBased</li> |
| <li>PDStream</li> |
| </ul> |
| |
| <p>The metadata that is stored in PDF objects conforms to the XMP specification, it is recommended that you review that specification. |
| Currently there is no high level API for managing the XML metadata, PDFBox uses standard java InputStream/OutputStream |
| to retrieve or set the XML metadata. For example:</p> |
| |
| <source> |
| PDDocument doc = PDDocument.load( ... ); |
| PDDocumentCatalog catalog = doc.getDocumentCatalog(); |
| PDMetadata metadata = catalog.getMetadata(); |
| |
| //to read the XML metadata |
| InputStream xmlInputStream = metadata.createInputStream(); |
| |
| //or to write new XML metadata |
| InputStream newXMPData = ...; |
| PDMetadata newMetadata = new PDMetadata(doc, newXMLData, false ); |
| catalog.setMetadata( newMetadata ); |
| </source> |
| </section> |
| </body> |
| </document> |