Set XMP Metadata of a PDF Document in C#/VB.NET

XMP is a file labeling technology that lets you embed metadata into files themselves during the content creation process. With an XMP enabled application, your workgroup can capture meaningful information about a project (such as titles and descriptions, searchable keywords, and up-to-date author and copyright information) in a format that is easily understood by your team as well as by software applications, hardware devices, and even file formats.

In the Spire.PDF Version 3.6.135 and above, we add a new feature to read, set and load an existing XMP data from XML documents. This article presents how to set XMP Metadata while creating a PDF document.

Code Snippet:

Step 1: Initialize a new instance of PdfDocument class.

PdfDocument doc = new PdfDocument();

Step 2: Get XMP metadata from PDF document.

XmpMetadata meta = doc.XmpMetaData;

Step 3: Set author, create data, creator, keywords and etc. to metadata.

meta.SetAuthor("E-iceblue");
meta.SetCreateDate(DateTime.Now);
meta.SetCreator("Spire.PDF");
meta.SetCustomProperty("Field", "NewValue");
meta.SetKeywords("XMP");
meta.SetProducer("E-icenlue Co,.Ltd");
meta.SetSubject("XMP Metadata");
meta.SetTitle("Set XMP Metadata in PDF");

Step 4: Save the file.

doc.SaveToFile("XMP.pdf", FileFormat.PDF);

Output:

To view metadata in a PDF document, open it with Acrobat or Acrobat Reader and select ‘Document Properties’ in the File menu.

Set XMP Matedata of a PDF Document in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Xmp;
using System;

namespace SetXMPMetadata
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            XmpMetadata meta = doc.XmpMetaData;

            meta.SetAuthor("E-iceblue");
            meta.SetCreateDate(DateTime.Now);
            meta.SetCreator("Spire.PDF");
            meta.SetCustomProperty("Field", "NewValue");
            meta.SetKeywords("XMP");
            meta.SetProducer("E-icenlue Co,.Ltd");
            meta.SetSubject("XMP Metadata");
            meta.SetTitle("Set XMP Metadata in PDF");

            doc.SaveToFile("XMP.pdf", FileFormat.PDF);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Xmp

Namespace SetXMPMetadata
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
Dim meta As XmpMetadata = doc.XmpMetaData

meta.SetAuthor("E-iceblue")
meta.SetCreateDate(DateTime.Now)
meta.SetCreator("Spire.PDF")
meta.SetCustomProperty("Field", "NewValue")
meta.SetKeywords("XMP")
meta.SetProducer("E-icenlue Co,.Ltd")
meta.SetSubject("XMP Metadata")
meta.SetTitle("Set XMP Metadata in PDF")
doc.SaveToFile("XMP.pdf", FileFormat.PDF)	
	   End Sub
	End Class
End Namespace