更改 XMP EPS 元数据中的简单值 |Java

要更改 EPS 文件的 XMP 元数据中的简单值,需要执行以下步骤:

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


以下代码片段展示了如何在 Java 中更改 EPS 文件的 XMP 元数据中的简单值:

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// Set license
 3new License().setLicense(BaseExamplesTest.LICENSE_PATH);
 4
 5  // The path to the documents directory.
 6  String dataDir = Utils.getDataDir();
 7  
 8  // Initialize input EPS file stream
 9  FileInputStream psStream = new FileInputStream(dataDir + "xmp1.eps");
10
11  PsDocument document = new PsDocument(psStream);
12
13  try {
14      // 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)
15      XmpMetadata xmp = document.getXmpMetadata();
16
17      // Change "ModifyDate" value
18      TimeZone.setDefault( TimeZone.getTimeZone("UTC"));
19      Date now = new Date();
20      xmp.put("xmp:ModifyDate", new XmpValue(now));
21      
22      // Change "creator" value
23      XmpValue value = new XmpValue("Aspose.Page");
24      xmp.put("dc:creator", value);
25
26      // Change "title" value
27      value = new XmpValue("(PAGEJAVA-29.eps)");
28      xmp.put("dc:title", value);
29      
30      
31      // Initialize output EPS file stream
32      FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp1_changed.eps");
33      
34      // Save document with changed XMP metadata
35			try {			
36				document.save(outPsStream);
37			} finally {
38				outPsStream.close();
39			}
40
41} finally {
42    // close input EPS stream
43		psStream.close();
44}

请参阅 .NETC++ 中 XMP 元数据中简单值的更改。

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.