Manage PDF Document Properties and XMP Metadata
- 9 minutes to read
PDF documents can store metadata in two formats:
- Document properties
Store common document information, such as the title, author, subject, keywords, creator, producer, and creation date. PDF viewers, search tools, and document management systems use these properties to identify and index PDF documents.
Use the DocumentInfo class to read and update document properties.
- XMP metadata
Adobe Extensible Metadata Platform (XMP) is an XML-based metadata standard created by Adobe. XMP defines a common metadata model that applications can embed into different file formats.
XMP metadata provides additional metadata beyond document properties and supports predefined and custom metadata schemas. The PDF Document API allows you to load XMP metadata from a file or string, edit existing metadata, create custom schemas, and access metadata nodes directly.
You can edit either format and synchronize their values to keep document metadata consistent.
Specify Document Properties
The PdfDocument.getMetadata() method returns a DocumentMetadata object that contains document metadata.
Use the DocumentMetadata.getDocumentInfo() method to access the following document properties:
| Document Property | Access Methods | Description |
|---|---|---|
| Title | getTitle() setTitle(String) |
Specifies the document title. |
| Author | getAuthor() setAuthor(String) |
Specifies the document author. |
| Subject | getSubject() setSubject(String) |
Specifies the document subject or brief description. |
| Keywords | getKeywords() setKeywords(String) |
Specifies keywords associated with the document. Separate multiple keywords with commas. |
| Creator | getCreator() setCreator(String) |
Specifies the application that created the original document. |
| Producer | getProducer() setProducer(String) |
Specifies the application or library that generated the PDF document. |
| CreatedAt | getCreatedAt() setCreatedAt(OffsetDateTime) |
Specifies the document creation date and time. |
| ModifiedAt | getModifiedAt() setModifiedAt(OffsetDateTime) |
Specifies the document modification date and time. |
| Custom Properties | getCustomProperties() | Returns custom document properties as a Map<String, String>. Add, modify, or remove entries in the returned map to manage custom properties. |
The following code snippet updates document properties in a PDF document:
import com.devexpress.docs.pdf.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
DocumentInfo documentInfo = pdfDocument.getMetadata().getDocumentInfo();
documentInfo.setTitle("Updated Document Title");
documentInfo.setAuthor("Updated Author Name");
documentInfo.setSubject("Updated Subject");
documentInfo.setKeywords("Updated, Keywords");
documentInfo.setProducer("Updated Producer");
documentInfo.setCreator("Updated Creator");
pdfDocument.getMetadata().setDocumentInfo(documentInfo);
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
}
}
Embed XMP Metadata
The DocumentMetadata.getXmp() method returns XMP metadata. You can load metadata from a stream or string, modify existing metadata, or create a new XMP metadata model.
Load XMP Metadata from a File or a String
Use one of the following methods to load XMP metadata:
- XmpMetadata.fromByteArray(byte[])
- XmpMetadata.fromString(java.lang.String)
- XmpMetadata.fromStream(java.io.InputStream)
The following code snippet loads XMP metadata from an XML file and embeds it into a PDF document:
import com.devexpress.docs.pdf.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream metadataStream = new FileInputStream("metadata.xml")) {
pdfDocument.getMetadata().setXmp(
XmpMetadata.fromStream(metadataStream)
);
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
}
}
Use XMP Schemas
An XMP schema (namespace) is a collection of metadata properties. Each schema has a unique namespace URI and can contain multiple properties. The XMP specification defines predefined schemas for general document information and application-specific metadata.
The PDF Document API supports the following predefined XMP namespaces:
| Namespace | Description | Namespace URI | Prefix | Class |
|---|---|---|---|---|
| Adobe XMP Basic | Contains basic descriptive information. | http://ns.adobe.com/xap/1.0/ | xmp |
XmpBasicSchema |
| Adobe PDF | Specifies Adobe PDF document properties. | http://ns.adobe.com/pdf/1.3/ | pdf |
XmpPdfSchema |
| PDF/A | Defines a document’s PDF/A conformance level and version. | https://www.aiim.org/pdfa/ns/id | pdfaid |
XmpPdfASchema |
| PDF/UA | Defines a document’s PDF/UA conformance level and version. | https://www.aiim.org/pdfua/ns/id | pdfua |
XmpPdfUASchema |
| Dublin Core | Contains information defined in the Dublin Core Metadata Set. | http://purl.org/dc/elements/1.1/ | dc |
XmpDublinCoreSchema |
| Rights Management | Contains information about legal restrictions associated with a PDF document. | http://ns.adobe.com/xap/1.0/rights/ | xmpRights |
XmpRightsManagementSchema |
The following code snippet creates a Rights Management schema and embeds it into a PDF document:
import com.devexpress.docs.pdf.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
// Create a new XMP metadata packet.
XmpMetadata metadata = new XmpMetadata();
XmpRightsManagementSchema rightsManagementSchema =
metadata.getXmpRightsManagementSchema();
rightsManagementSchema.setCertificate(
new XmpString("https://www.devexpress.com/")
);
rightsManagementSchema.setMarked(new XmpBool(true));
rightsManagementSchema.setWebStatement(
new XmpString("https://www.devexpress.com/support/eulas/")
);
rightsManagementSchema.getUsageTerms().add(
"en-US",
"Copyright(C) 2026 DevExpress. All Rights Reserved."
);
// Embed XMP metadata into the document.
pdfDocument.getMetadata().setXmp(metadata);
// Save the updated document.
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
}
}
Create Custom XMP Schemas
The XmpMetadata.getCustomSchema() method returns the custom XMP schema that stores application-defined metadata properties. Use the returned schema to read, add, update, or remove custom XMP metadata properties.
Note
Register a custom namespace with the XmpMetadata.registerNamespace() method before you add properties that belong to it. A custom namespace allows you to store application-specific metadata properties that are not available in predefined XMP schemas.
The following code snippet creates a custom XMP schema with the http://www.example.com/custom/1.0/ namespace URI and adds custom properties:
import com.devexpress.docs.pdf.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
// Create a new XMP metadata packet.
XmpMetadata metadata = new XmpMetadata();
// Register a custom XMP namespace.
metadata.registerNamespace(
"http://www.example.com/custom/1.0/",
"dx"
);
// Add custom metadata properties.
IXmpCustomSchema customSchema = metadata.getCustomSchema();
customSchema.set("Team", "Office");
customSchema.set("Checked", "true");
customSchema.set("Project", "PDF Document API");
// Embed the XMP metadata into the PDF document.
pdfDocument.getMetadata().setXmp(metadata);
// Save the updated document.
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
}
}
Manage Metadata Nodes
Use the XmpMetadata.getRawData() method to access XMP metadata as an XmpRawAccess object. This object allows you to work with XMP metadata properties as raw XML nodes.
Use XmpRawAccess methods to get, set, or remove property values. Identify a property as URI:name or prefix:name.
For example, you can use xmp:Identifier or http://ns.adobe.com/xap/1.0/:Identifier to access the Identifier property from the Basic XMP namespace.
Get Property Values
Call the XmpRawAccess.getString(String) method to get a property value.
The following code snippet loads XMP metadata from an XML file and gets Identifier and Rating property values from the Basic XMP namespace:
import com.devexpress.docs.pdf.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream metadataStream = new FileInputStream("metadata.xml")) {
pdfDocument.getMetadata().setXmp(
XmpMetadata.fromStream(metadataStream)
);
String identifier = pdfDocument.getMetadata()
.getXmp()
.getRawData()
.getString("xmp:Identifier");
String rating = pdfDocument.getMetadata()
.getXmp()
.getRawData()
.getString("xmp:Rating");
}
}
}
Set Property Values
Call the XmpRawAccess.setString(String, String) method to set a property value.
Note
The property must belong to the specified XMP namespace and support string values.
Use the XmpMetadata.registerNamespace(String, String) method to register a custom namespace to add properties that are not defined in predefined XMP schemas.
The following code snippet updates Label and CreatorTool properties in the Basic XMP namespace:
import com.devexpress.docs.pdf.*;
import java.io.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream metadataStream = new FileInputStream("metadata.xml")) {
pdfDocument.getMetadata().setXmp(
XmpMetadata.fromStream(metadataStream)
);
pdfDocument.getMetadata()
.getXmp()
.getRawData()
.setString("xmp:Label", "Updated Label");
pdfDocument.getMetadata()
.getXmp()
.getRawData()
.setString(
"xmp:CreatorTool",
"Updated Creator Tool"
);
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
}
}
Remove Properties
Call the XmpRawAccess.remove(String) method to remove a property from XMP metadata. Identify a property as URI:name or prefix:name.
The following code snippet removes Label and CreatorTool properties from the Basic XMP namespace:
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream metadataStream = new FileInputStream("metadata.xml")) {
pdfDocument.getMetadata().setXmp(
XmpMetadata.fromStream(metadataStream)
);
pdfDocument.getMetadata()
.getXmp()
.getRawData()
.remove("xmp:Label");
pdfDocument.getMetadata()
.getXmp()
.getRawData()
.remove("xmp:CreatorTool");
try (FileOutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
pdfDocument.save(outputStream);
}
}
Synchronize Document Properties and XMP Metadata
You can synchronize document properties with XMP metadata to keep document information consistent across both metadata formats.
Specify synchronization options when you load or save a PDF document, or call the DocumentMetadata.synchronize() method to synchronize metadata manually.
The PDF Document API supports the following synchronization modes:
| Mode | Description |
|---|---|
AUTO |
Synchronizes metadata automatically. If a property exists in both formats, the XMP metadata value takes precedence. |
INFO_TO_XMP |
Copies document properties to the corresponding XMP metadata properties. If a property exists in both formats, the document property value is used. |
XMP_TO_INFO |
Copies XMP metadata to the corresponding document properties. If a property exists in both formats, the XMP metadata value is used. |
Synchronize Metadata on Load
If a PDF document contains both document properties and XMP metadata, you can synchronize these metadata formats when the document is loaded.
To synchronize metadata when loading a document, do the following:
- Create a LoadOptions object.
- Call the LoadOptions.setSyncMetadata(true) to enable synchronization.
- Call the LoadOptions.setMetadataSyncMode(MetadataSyncMode) method and specify the synchronization direction.
- Pass the
LoadOptionsobject to thePdfDocumentconstructor.
The following code snippet synchronizes XMP metadata with document properties when a PDF document loads:
import com.devexpress.docs.pdf.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
LoadOptions loadOptions = new LoadOptions();
loadOptions.setSyncMetadata(true);
loadOptions.setMetadataSyncMode(MetadataSyncMode.XMP_TO_INFO);
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream, loadOptions)) {
// Process the PDF document.
}
}
}
Synchronize Metadata on Save
Specify the metadata synchronization mode in a SaveOptions object and pass it to the PdfDocument.save() method.
The following code snippet synchronizes document properties with XMP metadata after merging PDF documents:
import com.devexpress.docs.pdf.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
OutputStream outputStream = new FileOutputStream("UpdatedDocument.pdf")) {
// Process the PDF document.
SaveOptions saveOptions = new SaveOptions();
saveOptions.setMetadataSyncMode(MetadataSyncMode.INFO_TO_XMP);
pdfDocument.save(outputStream, saveOptions);
}
}
}
Synchronize Metadata Manually
Call the DocumentMetadata.synchronize() method to synchronize metadata on demand.
Manual synchronization is useful when you modify document metadata after operations such as merging PDF documents.
The following code snippet synchronizes document properties with XMP metadata after merging PDF documents:
import com.devexpress.docs.pdf.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = new FileInputStream("Document1.pdf");
PdfDocument pdfDocument = new PdfDocument(inputStream);
InputStream documentStream = new FileInputStream("Document2.pdf")) {
pdfDocument.appendDocument(documentStream);
pdfDocument.getMetadata().synchronize(
MetadataSyncMode.INFO_TO_XMP
);
}
}
}