在 EPS 的 XMP 元数据中添加 XML 命名空间 |Java

为了在 EPS 文件的 XMP 元数据中添加 XML 命名空间,需要执行以下步骤:

  1. 初始化用于输入 EPS 文件的输入流。
  2. 从先前创建的输入流创建 PsDocument 的实例。
  3. 从 PsDocument 获取 XmpMetadata 的实例。如果给定的 EPS 文件不包含 XMP 元数据,则将创建新的实例,并使用 PS 元数据注释中的值填充该实例并返回给您。
  4. 现在,您可以向元数据添加新的 XML 命名空间。
  5. 初始化用于输出 EPS 文件的输出流。
  6. 保存包含更改后的 XMP 元数据的 EPS 文件。


以下代码片段展示了如何在 Java 中向 EPS 文件的 XMP 元数据中添加 XML 命名空间:

 1// Set license
 2new License().setLicense(BaseExamplesTest.LICENSE_PATH);
 3
 4// The path to the documents directory.
 5String dataDir = Utils.getDataDir();
 6
 7// Initialize input EPS file stream
 8FileInputStream psStream = new FileInputStream(dataDir + "xmp3.eps");
 9
10PsDocument document = new PsDocument(psStream);
11
12try {
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    // Add new XML namespace "http://www.some.org/schema/tmp#" with prefix "tmp"
17    xmp.registerNamespaceURI("tmp", "http://www.some.org/schema/tmp#");
18    
19    //Add new property "tmp:newKey" in new XML namespace
20    xmp.put("tmp:newKey", new XmpValue("NewValue"));
21    
22    
23    // Initialize output EPS file stream
24    FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp3_changed.eps");
25    
26    // Save document with changed XMP metadata
27		try {			
28			document.save(outPsStream);
29		} finally {
30			outPsStream.close();
31		}
32
33} finally {
34    // close input EPS stream
35		psStream.close();
36}

请参阅 .NETC++ 中的 XMP 元数据中添加 XMl 命名空间。

您可以从 GitHub下载示例和数据文件。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.