在 EPS | .NET 的 XMP 元数据中添加 XML 命名空间
您可以使用 Metadata 网页应用
为了在 EPS 文件的 XMP 元数据中添加 XML 命名空间,需要执行以下步骤:
- 初始化用于输入 EPS 文件的输入流。
- 从先前创建的输入流创建 PsDocument 实例。
- 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则会创建新的实例,并使用 PS 元数据注释中的值填充该实例,然后返回给您。
- 现在,您可以向元数据添加新的 XML 命名空间了。
- 初始化输出 EPS 文件的输出流。
- 保存更改后的 XMP 元数据的 EPS 文件。
以下代码片段展示了如何在 C# 中向 EPS 文件的 XMP 元数据添加 XML 命名空间:
1// Add namespace in XMP metadata in EPS document.
2
3// Initialize EPS file input stream
4System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_simple_props_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
5
6// Create PsDocument instance from stream
7PsDocument document = new PsDocument(psStream);
8
9string outputFileName = "add_xmp_namespace_out.eps";
10
11try
12{
13 // 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)
14 XmpMetadata xmp = document.GetXmpMetadata();
15
16 //Change XMP metadata values
17
18 // Add new XML namespace "tmp".
19 xmp.RegisterNamespaceUri("tmp", "http://www.some.org/schema/tmp#");
20
21 // Add new string property in new namespace.
22 xmp.Add("tmp:newKey", new XmpValue("NewValue"));
23
24 // Save EPS file with changed XMP metadata
25
26 // Create ouput stream
27 using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
28 {
29 // Save EPS file
30 document.Save(outPsStream);
31 }
32}
33finally
34{
35 psStream.Close();
36}
在我们的 Metadata 应用程序上在线评估 XMP 元数据的运行情况。
您可以从 GitHub下载示例和数据文件。