Skip to main content
All docs
V26.1
  • New PDF Document API: Specify Basic and XMP Metadata

    • 8 minutes to read

    The new PDF Document API allows you to specify both basic and XMP metadata for PDF documents. You can also synchronize basic metadata with XMP metadata to keep both formats consistent.

    Basic Metadata
    Use the PdfDocumentInfo class to set basic metadata properties such as Title, Author, Subject, and Keywords. Basic metadata provides information about a PDF document that PDF readers and search engines can use.
    XMP Metadata
    Adobe Extensible Metadata Platform (XMP) is an XML-based ISO metadata standard created by Adobe Systems Inc. It defines the data structure, serialization model, and basic metadata properties for a unified metadata package that can be embedded in different media formats.

    Specify Basic Metadata

    The PdfDocument.Metadata property obtains both basic and XMP metadata. Use the DocumentMetadata.DocumentInfo property to specify basic metadata information (author, title, subject, keywords, and so on).

    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);
        }
    }
    

    Embed 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.

    Load XMP Metadata from a File or a String

    Use one of the following methods to load XMP metadata:

    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);
        }
    }
    

    Use XMP Schemas

    An XMP schema, or namespace, is a set of metadata properties. Each schema is identified by a unique namespace URI and can contain any number of properties. The XMP specification defines predefined schemas, including standard general-purpose namespaces and namespaces specialized for Adobe applications.

    PDF Document API supports the following predefined XMP namespaces:

    Namespace Description Credentials Class
    Basic XMP Contains basic description information. Namespace URI: http://ns.adobe.com/xap/1.0/
    Prefix: xmp
    XmpBasicSchema
    Adobe PDF Specifies properties used in Adobe PDF documents. Namespace URI: http://ns.adobe.com/pdf/1.3/
    Prefix: pdf
    XmpPdfSchema
    PDF/A Defines a document’s PDF/A conformance level and version. Namespace URI: https://www.aiim.org/pdfa/ns/id
    Prefix: pdfaid
    XmpPdfASchema
    PDF/UA Defines a document’s PDF/UA conformance level and version. Namespace URI: https://www.aiim.org/pdfua/ns/id
    Prefix: pdfua
    XmpPdfUASchema
    Dublin Core Contains information defined in the Dublin Core Metadata Set, created by the Dublin Core Metadata Initiative (DCMI). Namespace URI: http://purl.org/dc/elements/1.1/_
    Prefix: dc
    XmpDublinCoreSchema
    Rights Management Contains information regarding the legal restrictions associated with a PDF document. Namespace URI: http://ns.adobe.com/xap/1.0/rights/
    Prefix: xmpRights
    XmpRightsManagementSchema

    The following code snippet creates the Rights Management schema and embeds it into a PDF document:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf"))) {
        // Create a new XMP packet:
        XmpMetadata metadata = new XmpMetadata();
        XmpRightsManagementSchema rightsManagementSchema =
            metadata.XmpRightsManagementSchema;
        rightsManagementSchema.Certificate = new XmpString("https://www.devexpress.com/");
        rightsManagementSchema.Owner.Add(new XmpString("DevExpress"));
        rightsManagementSchema.Marked = true;
        rightsManagementSchema.WebStatement = new XmpString("https://www.devexpress.com/support/eulas/");
        rightsManagementSchema.UsageTerms.Add("EN-US", "Copyright(C) 2026 DevExpress.All Rights Reserved.");
    
        // Embed metadata in the document:
        pdfDocument.Metadata.Xmp = metadata;
    }
    

    Create Custom XMP Schemas

    Create a new XmpCustomSchema and set it as the DocumentMetadata.Xmp property value. Use the XmpCustomSchema properties and methods to manage custom metadata properties.

    The following code snippet creates a custom XMP schema with the “http://www.example.com/custom/1.0/“ namespace URI and adds custom properties to this schema:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf"))) {
        XmpMetadata metadata = new XmpMetadata();
        XmpCustomSchema customSchema = metadata.CustomSchema;
        metadata.RegisterNamespace("http://www.example.com/custom/1.0/", "dx");
    
        customSchema["Team"] = "Office";
        customSchema["Checked"] = "true";
        customSchema["Project"] = "PDF Document API";
    
        // Embed metadata in the document:
        pdfDocument.Metadata.Xmp = metadata;
    }
    

    Manage Metadata Nodes

    Use the XmpMetadata.RawData property to obtain XMP metadata as an XmpRawAccess object. This object allows you to access XMP metadata properties as raw XML nodes. You can use the XmpRawAccess methods to get, set, or remove property values. Identify properties as “URI:name” or “prefix:name”.

    Obtain Property Values

    Call the XmpRawAccess.GetString(String) method to obtain a property value. Identify a property as “URI:name” or “prefix:name”.

    The following code snippet obtains “Identifier” and “Rating” property values from the Basic XMP namespace:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    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);
            string identifier = pdfDocument.Metadata.Xmp.RawData.GetString("xmp:Identifier");
            string rating = pdfDocument.Metadata.Xmp.RawData.GetString("xmp:Rating");
        }
    }
    

    Set Property Values

    Use the XmpRawAccess.SetString(String, String) method to set a property value. Identify the property as “URI:name” or “prefix:name”.

    Make sure the property is defined in the specified XMP namespace and supports string values. Call the XmpMetadata.RegisterNamespace(String, String) method to register a custom namespace if you want to use properties that are not defined in the predefined XMP namespaces.

    The following code snippet sets “Label” and “Creator Tool” property values in the Basic XMP namespace:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    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);
            pdfDocument.Metadata.Xmp.RawData.SetString("xmp:Label", "Updated Label");
            pdfDocument.Metadata.Xmp.RawData.SetString("xmp:CreatorTool", "Updated Creator Tool");
        }
    }
    

    Remove Properties

    Call the XmpRawAccess.Remove(String) method to remove a property. Identify properties as “URI:name” or “prefix:name”. .

    The following code snippet removes the “Label” and “Creator Tool” properties from the Basic XMP namespace:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    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);
            pdfDocument.Metadata.Xmp.RawData.Remove("xmp:Label");
            pdfDocument.Metadata.Xmp.RawData.Remove("xmp:CreatorTool");
        }
    }
    

    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.

    Synchronize Metadata on Load

    Specify LoadOptions.SyncMetadata and LoadOptions.MetadataSyncMode properties and pass the LoadOptions object as a PdfDocument constructor parameter.

    The following code snippet synchronizes basic metadata with XMP metadata when opening a PDF document:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf"), 
            new LoadOptions { MetadataSyncMode = MetadataSyncMode.XmpToInfo})) {
        // process the document
    }
    

    Synchronize Metadata on Save

    Specify SaveOptions.SyncMetadata and SaveOptions.MetadataSyncMode properties and pass the SaveOptions object as the PdfDocument.Save method parameter.

    The following code snippet synchronizes basic metadata with XMP metadata when saving a PDF document:

    using DevExpress.Docs.Pdf;
    using System.IO;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf"))) {
        // process the document
        SaveOptions saveOptions = new SaveOptions
        {
            MetadataSyncMode = MetadataSyncMode.InfoToXmp
        };
        using (FileStream stream =
        File.Create("UpdatedDocument.pdf"))
        {
            pdfDocument.Save(stream, saveOptions);
        }
    }
    

    Synchronize Metadata Manually

    Call the DocumentMetadata.Synchronize method to synchronize metadata on demand.

    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);
    }