Back to Devexpress

PdfDocument.SetMetadata(XmpDocument) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocument-dot-setmetadata-x28-devexpress-dot-pdf-dot-xmp-dot-xmpdocument-x29.md

latest3.9 KB
Original Source

PdfDocument.SetMetadata(XmpDocument) Method

Embeds metadata in a document.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public void SetMetadata(
    XmpDocument xmpDocument
)
vb
Public Sub SetMetadata(
    xmpDocument As XmpDocument
)

Parameters

NameTypeDescription
xmpDocumentXmpDocument

An XMP packet.

|

Remarks

The SetMetadata method allows you to embed XMP metadata in the document. You can pass a string with metadata or an XmpDocument object to this method.

The XmpDocument object is an instance of the XMP data model (XMP packet). You can load data to the packet from a stream or a string.

Example

The code sample below loads metadata from a file and embeds it in the document:

csharp
using DevExpress.Pdf;
using DevExpress.Pdf.Xmp;
//...

using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
    pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf");
    PdfDocument document = pdfDocumentProcessor.Document;
    XmpDocument metadata = new XmpDocument();
    using (FileStream xmlStream = new FileStream("Documents//metadata.xml", FileMode.Open, FileAccess.Read))
    {
        metadata = XmpDocument.FromStream(xmlStream);
        document.SetMetadata(metadata);
    }

    pdfDocumentProcessor.SaveDocument("Invoice_Upd.pdf");
}
vb
Imports DevExpress.Pdf
Imports DevExpress.Pdf.Xmp
'...

Using pdfDocumentProcessor As New PdfDocumentProcessor()
    pdfDocumentProcessor.LoadDocument("Documents//Invoice.pdf")
    Dim document As PdfDocument = pdfDocumentProcessor.Document
    Dim metadata As New XmpDocument()
    Using xmlStream As New FileStream("Documents//metadata.xml", FileMode.Open, FileAccess.Read)
        metadata = XmpDocument.FromStream(xmlStream)
        document.SetMetadata(metadata)
    End Using

    pdfDocumentProcessor.SaveDocument("Invoice_Upd.pdf")
End Using

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetMetadata(XmpDocument) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-xmp-example/CS/XmpMetadataExamples/Program.cs#L51

csharp
// Embed modified metadata to the document:
document.SetMetadata(editedMetadata);

pdf-document-api-xmp-example/VB/XmpMetadataExamples/Program.vb#L41

vb
' Embed modified metadata to the document:
document.SetMetadata(editedMetadata)
' Save the result:

See Also

PdfDocument Class

PdfDocument Members

DevExpress.Pdf Namespace