更改 EPS 的 XMP 元数据中的数组项 | Python

要更改 EPS 文件的 XMP 元数据中的数组项,您需要执行以下步骤:

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


这里有一个代码片段,展示了如何使用 Python 更改 EPS 文件的 XMP 元数据中的数组项:

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
 3# Initialize an EPS file input stream
 4ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
 5# Create a PsDocument instance from stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # Get XMP metadata. If EPS file doesn't contain any XMP metadata we get a new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
10    xmp = document.get_xmp_metadata()
11    
12    #Change the XMP metadata values
13    
14    # Change the title item at index 0
15    xmp.set_array_item("dc:title", 0, XmpValue("NewTitle"))
16    
17    # Change the creator item at index 0
18    xmp.set_array_item("dc:creator", 0, XmpValue("NewCreator"))
19    
20    # Save the EPS file with the changed XMP metadata
21    
22    # Create an ouput stream
23    with open(data_dir + "change_array_items_output.eps", "wb") as out_ps_stream:
24        # Save EPS file
25        document.save(out_ps_stream)
26    
27finally:
28    ps_stream.close()

请参阅 .NETJavaC++ 中 XMP 元数据中数组项的更改。

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.