officefileapi-devexpress-dot-pdf-dot-pdfdocument-dot-setmetadata-x28-devexpress-dot-pdf-dot-xmp-dot-xmpdocument-x29.md
Embeds metadata in a document.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Core.dll
NuGet Package : DevExpress.Pdf.Core
public void SetMetadata(
XmpDocument xmpDocument
)
Public Sub SetMetadata(
xmpDocument As XmpDocument
)
| Name | Type | Description |
|---|---|---|
| xmpDocument | XmpDocument |
An XMP packet.
|
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.
The code sample below loads metadata from a file and embeds it in the document:
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");
}
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
// Embed modified metadata to the document:
document.SetMetadata(editedMetadata);
pdf-document-api-xmp-example/VB/XmpMetadataExamples/Program.vb#L41
' Embed modified metadata to the document:
document.SetMetadata(editedMetadata)
' Save the result:
See Also