使用 .NET 从 EPS 文件获取 XMP 元数据
您可以使用 Metadata Web 应用检查 Aspose.Page XMP Metadata 的质量。
为了从 EPS 文件中提取 XMP 元数据,需要执行以下步骤:
- 初始化用于输入 EPS 文件的输入流。
- 从先前创建的输入流创建 PsDocument 实例。
- 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则将创建新的实例,并使用 PS 元数据注释中的值填充该实例并返回给您。
- 现在您可以查看元数据字段的值了。
以下代码片段展示了如何在 C# 中从 EPS 文件中提取 XMP 元数据:
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}
在我们的 Metadata 应用程序上在线评估 XMP 元数据。
您可以从 GitHub下载示例和数据文件。