更改 EPS 的 XMP 元数据中的数组项 | Java
要更改 EPS 文件的 XMP 元数据中的数组项,需要执行以下步骤:
- 为输入 EPS 文件初始化输入流。
- 从先前创建的输入流创建 PsDocument 实例。
- 从 PsDocument 获取 XmpMetadata 实例。如果给定的 EPS 文件不包含 XMP 元数据,则将创建新的实例,并使用 PS 元数据注释中的值填充该实例并返回给您。
- 现在您可以更改数组元数据字段中的项。
- 为输出 EPS 文件初始化输出流。
- 保存包含更改后的 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.
6String dataDir = Utils.getDataDir();
7
8// Initialize input EPS file stream
9FileInputStream psStream = new FileInputStream(dataDir + "xmp3.eps");
10
11PsDocument document = new PsDocument(psStream);
12
13try {
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 // Set "dc:title" array item by index 0
18 xmp.setArrayItem("dc:title", 0, new XmpValue("NewTitle"));
19
20 // Set "dc:creator" array item by index 0
21 xmp.setArrayItem("dc:creator", 0, new XmpValue("NewCreator"));
22
23
24 // Initialize output EPS file stream
25 FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp3_changed.eps");
26
27 // Save document with changed XMP metadata
28 try {
29 document.save(outPsStream);
30 } finally {
31 outPsStream.close();
32 }
33
34} finally {
35 // close input EPS stream
36 psStream.close();
37}
您可以从 GitHub下载示例和数据文件。