在 EPS 的 XMP 元数据中添加属性 | .NET
您可以使用 Metadata 网页应用
为了在 EPS 文件的 XMP 元数据中添加属性,需要执行以下步骤:
- 初始化用于输入 EPS 文件的输入流。
- 从先前创建的输入流创建 PsDocument 实例。
- 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则会创建新的实例,并使用 PS 元数据注释中的值填充该实例,然后返回给您。
- 现在您可以添加元数据字段的属性了。
- 初始化输出 EPS 文件的输出流。
- 保存更改后的 XMP 元数据的 EPS 文件。
以下代码片段展示了如何在 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 + "add_props_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 //Change XMP metadata values
15
16 DateTime now = DateTime.UtcNow;
17
18 // Add Integer poperty
19 xmp.Add("xmp:Intg1", new XmpValue(111));
20
21 // Add DateTime poperty
22 xmp.Add("xmp:Date1", new XmpValue(now));
23
24 // Add Double poperty
25 xmp.Add("xmp:Double1", new XmpValue(111.11D));
26
27 // Add String poperty
28 xmp.Add("xmp:String1", new XmpValue("ABC"));
29
30 // Save EPS file with changed XMP metadata
31
32 // Create ouput stream
33 using (System.IO.FileStream outPsStream = new System.IO.FileStream(dataDir + "add_props_output.eps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
34 {
35 // Save EPS file
36 document.Save(outPsStream);
37 }
38
39}
40finally
41{
42 psStream.Close();
43}
在我们的Metadata应用程序上在线评估 XMP 元数据。
您可以从 GitHub下载示例和数据文件。