Manage PDF Document Properties and XMP Metadata
- 10 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. |
| Trapped | getTrapped() setTrapped(Boolean) |
Specifies whether the document includes trapping information for commercial printing. |
| 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. | http://www.aiim.org/pdfa/ns/id/ | pdfaid |
XmpPdfASchema |
| PDF/UA | Defines a document’s PDF/UA conformance level and version. | http://www.aiim.org/pdfua/ns/id/ | pdfuaid |
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);
}
}
}
}
Specify PDF/A and PDF/UA Conformance
PDF/A and PDF/UA identification schemas declare the standards that a document conforms to. Call the DocumentMetadata.setPdfACompatibility(value) or DocumentMetadata.setPdfUACompatibility(value) method to write the PDF/A or PDF/UA conformance level to XMP metadata. These methods also copy non-empty title, author, subject, keywords, creator, producer, and date properties to XMP metadata.
Note
setPdfACompatibility and setPdfUACompatibility methods declare conformance and do not modify document content.
DocumentMetadata.getPdfACompatibility() and DocumentMetadata.getPdfUACompatibility() methods return conformance levels declared by a document. The following code snippet loads a document and prints its PDF/A and PDF/UA conformance levels:
import java.io.*;
import java.nio.file.*;
import com.devexpress.docs.pdf.*;
public class Main {
public static void main(String[] args) throws Exception {
try (InputStream inputStream = Files.newInputStream(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(inputStream)) {
DocumentMetadata metadata = pdfDocument.getMetadata();
System.out.println("PDF/A: " + metadata.getPdfACompatibility());
System.out.println("PDF/UA: " + metadata.getPdfUACompatibility());
}
}
}
Refer to the following help topic for additional information: Convert and Validate PDF/A and PDF/UA Documents — PDF Document API for Java.
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
Call the XmpMetadata.registerNamespace() method to specify the prefix of a custom namespace. 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("http://www.example.com/custom/1.0/");
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 prefix:name.
For example, you can use xmp: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 prefix must refer to a namespace that the XMP metadata contains. If the XMP metadata does not contain the namespace yet (including predefined namespaces in a new XmpMetadata object), call the XmpMetadata.registerNamespace(String, String) method first.
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 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 in a direction that depends on the document content. If the document contains XMP metadata, copies XMP metadata to basic document information (as XMP_TO_INFO does). Otherwise, copies basic document information to XMP metadata (as INFO_TO_XMP does). |
| XMP_TO_INFO | Copies XMP metadata to the corresponding basic document information properties. The API clears basic information properties that have no XMP value. |
| INFO_TO_XMP | Copies basic document information to the corresponding XMP metadata properties (the API creates XMP metadata if the document has none). The API clears XMP properties that have no basic information value. |
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
Create a SaveOptions object, call its setSyncMetadata(true) method, specify the synchronization mode, and pass the object to the PdfDocument.save() method.
The following code snippet synchronizes document properties with XMP metadata when it saves the document:
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.setSyncMetadata(true);
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
);
}
}
}