更改 XMP EPS 元数据中的简单值 |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 a EPS file input stream
 4ps_stream = open(data_dir + "get_input.eps", "rb",)
 5# Create PsDocument instance from stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # Get XMP metadata. If EPS file doesn't contain 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 ModifyDate value
15    now = datetime.utcnow()
16    #xmp["xmp:ModifyDate"] = now
17    xmp.add("xmp:ModifyDate", now)
18    
19    # Change Creator value
20    value = XmpValue("Aspose.Page")
21    xmp.add("dc:creator", value)
22    
23    # Change Title value
24    value = XmpValue("(PAGEJAVA-29.eps)")
25    xmp.add("dc:title", value)
26    
27    # Save EPS file with changed XMP metadata
28    
29    # Create an ouput stream
30    with open(data_dir + "change_values_output.eps", "wb") as out_ps_stream:
31        # Save EPS file
32        document.save(out_ps_stream)
33    
34finally:
35    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.