PdfDocument.Metadata Property
Gets or sets the metadata of a PDF document.
Namespace: DevExpress.Docs.Pdf
Assembly: DevExpress.Docs.Pdf.v26.1.dll
Declaration
Property Value
| Type | Description |
|---|---|
| DocumentMetadata | An object that contains PDF metadata. |
Remarks
The Metadata property obtains both basic and XMP metadata. Basic metadata (Title, Author, Subject, and Keywords) provides information about a PDF document that PDF readers and search engines can use. XMP metadata is a more advanced format that allows you to store additional information about the document, such as the creation date, modification date, and custom properties.
Basic Metadata
Use the DocumentMetadata.DocumentInfo property to specify basic metadata information (author, title, subject, keywords, etc.).
The following code snippet specifies basic metadata for a PDF document:
using DevExpress.Docs.Pdf;
using System.IO;
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"document_001.pdf"))) {
DocumentInfo documentInfo = pdfDocument.Metadata.DocumentInfo;
documentInfo.Title = "Updated Document Title";
documentInfo.Author = "Updated Author Name";
documentInfo.Subject = "Updated Subject";
documentInfo.Keywords = "Updated, Keywords";
documentInfo.Producer = "Updated Producer";
using (FileStream stream =
File.Create("UpdatedDocument.pdf"))
{
pdfDocument.Save(stream);
}
}
XMP Metadata
The DocumentMetadata.Xmp property contains XMP metadata. You can load metadata from a stream or string, edit existing metadata, or generate a new XMP data model.
The following code snippet loads XMP metadata from a file and embeds it into a PDF document:
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"document_001.pdf"))) {
using (FileStream xmlStream = new FileStream("Documents//metadata.xml", FileMode.Open, FileAccess.Read))
{
pdfDocument.Metadata.Xmp = XmpMetadata.FromStream(xmlStream);
}
}
A PDF Document API supports multiple XMP schemas, including custom schemas. Refer to the following topic for more information on working with XMP metadata: New PDF Document API: Specify Basic and XMP Metadata
Synchronize Basic and XMP Metadata
You can synchronize basic metadata with XMP metadata so that both formats contain consistent information. You can specify synchronization options when loading or saving a document, or by calling the synchronization method.
The following synchronization modes are available:
- Basic to Xmp: Synchronizes basic metadata with XMP metadata. If a property value is specified in both formats, the basic metadata value is used.
- Xmp to basic: Synchronizes XMP metadata with basic metadata. If a property value is specified in both formats, the XMP metadata value is used.
- Automatic: Synchronizes basic metadata with XMP metadata. If a property value is specified in both formats, the XMP metadata value is used.
The following code snippet synchronizes basic metadata with XMP metadata after merging two PDF documents:
using DevExpress.Docs.Pdf;
using System.IO;
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"document_001.pdf")))
{
pdfDocument.AppendDocument(File.OpenRead(@"document_002.pdf"));
pdfDocument.Metadata.Synchronize(MetadataSyncMode.InfoToXmp);
}