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:
- Open a
FileStream(orusingstatement) for the EPS file, e.g.,using var stream = new FileStream("sample.eps", FileMode.Open);. - Create a
PsDocumentfrom the stream:var document = new PsDocument(stream);. - Retrieve the XMP metadata via
XmpMetadata xmp = document.XmpMetadata;. If the EPS does not contain XMP, Aspose creates a newXmpMetadataobject populated from the PS comments. - Access the metadata properties such as
xmp.Title,xmp.Author,xmp.Descriptionto read the values.
The following code snippet shows how to extract XMP metadata from EPS file in C#:
1// Get XMP metadata from EPS document.
2
3// Create PsDocument instance from file
4PsDocument document = new PsDocument(DataDir + "get_input.eps");
5
6// 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)
7XmpMetadata xmp = document.GetXmpMetadata();
8
9// Get "CreatorTool" value
10if (xmp.Contains("xmp:CreatorTool"))
11 Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
12
13// Get "CreateDate" value
14if (xmp.Contains("xmp:CreateDate"))
15 Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
16
17// Get a width of a thumbnail image if exists
18if (xmp.Contains("xmp:Thumbnails") && xmp["xmp:Thumbnails"].IsArray)
19{
20 XmpValue val = xmp["xmp:Thumbnails"].ToArray()[0];
21 if (val.IsNamedValues && val.ToDictionary().ContainsKey("xmpGImg:width"))
22 Console.WriteLine($"Thumbnail Width: {val.ToDictionary()["xmpGImg:width"].ToInteger()}");
23}
24
25// Get "format" value
26if (xmp.Contains("dc:format"))
27 Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
28
29// Get "DocumentID" value
30if (xmp.Contains("xmpMM:DocumentID"))
31 Console.WriteLine("DocumentID: " + xmp["xmpMM:DocumentID"].ToStringValue());Evaluate XMP metadata working online on our Metadata application.
You can download examples and data files from GitHub.