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:
- Initialize an input stream for input EPS file.
- Create an instance of PsDocument from created earlier input stream.
- 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.
- Now you can view values of metadata fields.
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.