DocumentMetadata Class
Contains document metadata.
Declaration
public class DocumentMetadata extends JavaObject
Remarks
PDF documents can store metadata in two formats: Document Properties and XMP Metadata. You can edit either format and synchronize their values to keep document metadata consistent.
The PdfDocument.getMetadata() method returns a DocumentMetadata object that contains document metadata.
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);
}
}
}
}
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.
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);
}
}
}
}
Refer to the following help topic for additional information: Manage PDF Document Properties and XMP Metadata.
Inherited Members
Inheritance
DocumentMetadata()
Initializes a new instance of the DocumentMetadata class.
Declaration
public DocumentMetadata()
Methods
getDocumentInfo() Method
Returns the information about document properties, such as the title, author, subject, and keywords.
Declaration
public DocumentInfo getDocumentInfo()
Returns
| Type | Description |
|---|---|
| DocumentInfo | The document information. |
Remarks
Refer to the following help topic for additional information: Specify Document Properties.
getXmp() Method
Returns the XMP metadata associated with the PDF document.
Declaration
public XmpMetadata getXmp()
Returns
| Type | Description |
|---|---|
| XmpMetadata | The XMP metadata of the PDF document. |
Remarks
Refer to the following help topic for additional information: Embed XMP Metadata.
setDocumentInfo(DocumentInfo value) Method
Sets the information about document properties, such as the title, author, subject, and keywords.
Declaration
public void setDocumentInfo(DocumentInfo value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | DocumentInfo | The document information. |
Remarks
Refer to the following help topic for additional information: Specify Document Properties.
setXmp(XmpMetadata value) Method
Sets the XMP metadata associated with the PDF document.
Declaration
public void setXmp(XmpMetadata value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | XmpMetadata | The XMP metadata of the PDF document. |
Remarks
Refer to the following help topic for additional information: Embed XMP Metadata.
synchronize(MetadataSyncMode mode) Method
Synchronizes document properties with XMP metadata.
Declaration
public void synchronize(MetadataSyncMode mode)
Parameters
| Name | Type | Description |
|---|---|---|
| mode | MetadataSyncMode | The synchronization mode. |
Remarks
Specify synchronization options when you load or save a PDF document, or call the DocumentMetadata.synchronize() method to synchronize metadata manually.
Refer to the following help topic for additional information: Synchronize Document Properties and XMP Metadata.