Add XMP metadata to EPS file using .NET

You can check the quality of Aspose.Page XMP Metadata working with Metadata web app

In order to add XMP metadata to EPS file it is necessary to do several steps:

  1. Initialize an input stream for input EPS file.
  2. Create an instance of PsDocument from created earlier input stream.
  3. Get an instance of XmpMetadata from the PsDocument. If given EPS file doesn’t contain XMP metadata the new one will be created, filled in with values from PS metadata comments and returned to you.
  4. Now you can view values of metadata fields.
  5. Initialize an output stream for output EPS file.
  6. Save EPS file with new XMP metadata.


Following code snippet shows how to add XMP metadata to EPS file in C#:

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-.NET
 2// The path to the documents directory.
 3string dataDir = RunExamples.GetDataDir_WorkingWithXMPMetadataInEPS();
 4// Initialize EPS file input stream
 5System.IO.FileStream psStream = new System.IO.FileStream(dataDir + "add_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
 6// Create PsDocument instance from stream
 7PsDocument document = new PsDocument(psStream);            
 8
 9try
10{
11    // Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
12    XmpMetadata xmp = document.GetXmpMetadata();
13
14    // Check metadata values extracted from PS metadata comments and set up in new XMP metadata
15
16    // Get "CreatorTool" value
17    if (xmp.Contains("xmp:CreatorTool"))
18        Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
19
20    // Get "CreateDate" value
21    if (xmp.Contains("xmp:CreateDate"))
22        Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
23
24    // Get "format" value
25    if (xmp.Contains("dc:format"))
26        Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
27
28    // Get "title" value
29    if (xmp.Contains("dc:title"))
30        Console.WriteLine("Title: " + xmp["dc:title"].ToArray()[0].ToStringValue());
31
32    // Get "creator" value
33    if (xmp.Contains("dc:creator"))
34        Console.WriteLine("Creator: " + xmp["dc:creator"].ToArray()[0].ToStringValue());
35
36    // Get "MetadataDate" value
37    if (xmp.Contains("xmp:MetadataDate"))
38        Console.WriteLine("MetadataDate: " + xmp["xmp:MetadataDate"].ToStringValue());
39
40    // Save EPS file with new XMP metadata
41    
42    // Create ouput stream
43    using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "add_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
44    {
45        // Save EPS file
46        document.Save(outPsStream);
47    }
48
49}
50finally
51{
52    psStream.Close();
53}

See adding XMP metadata in Java and C++.

Evaluate XMP metadata working online on our Metadata application.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.