Get XMP metadata from EPS file using .NET

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

In order to extract XMP metadata from 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.

Following code snippet shows how to extract XMP metadata from 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 + "get_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    // Get "CreatorTool" value
15    if (xmp.Contains("xmp:CreatorTool"))
16        Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
17    
18    // Get "CreateDate" value
19    if (xmp.Contains("xmp:CreateDate"))
20        Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
21
22    // Get a width of a thumbnail image if exists
23    if (xmp.Contains("xmp:Thumbnails") && xmp["xmp:Thumbnails"].IsArray)
24    {
25        XmpValue val = xmp["xmp:Thumbnails"].ToArray()[0];
26        if (val.IsNamedValues && val.ToDictionary().ContainsKey("xmpGImg:width"))
27            Console.WriteLine("Thumbnail Width: " + val.ToDictionary()["xmpGImg:width"].ToInteger());
28    }
29
30    // Get "format" value
31    if (xmp.Contains("dc:format"))
32        Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
33
34    // Get "DocumentID" value
35    if (xmp.Contains("xmpMM:DocumentID"))
36        Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());
37
38}
39finally
40{
41    psStream.Close();
42}

See extracting XMP metadata in Java and C++.

Evaluate XMP metadata working online on our Metadata application.

You can download examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.