Add array items in XMP metadata of EPS| Python
To add array items to the XMP metadata of an EPS file, you need to follow these steps:
- Initialize an input stream for input EPS file.
- Create an instance of PsDocument from the previously created input stream.
- Obtain an instance of XmpMetadata from the PsDocument. If the EPS file does not contain XMP metadata, a new one will be created and populated with values from PS metadata comments, then returned to you.
- You can now add items to the array metadata fields.
- Initialize an output stream for the output EPS file.
- Save the EPS file with the updated XMP metadata.
Here is a code snippet demonstrating how to add array items to the XMP metadata in an EPS file in Python:
1from aspose.page.eps import *
2from aspose.page.eps.xmp import *
3from util import Util
4###############################################
5###### Class and Method declaration here ######
6###############################################
7
8# The path to the documents directory.
9data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
10# Initialize the EPS file input stream
11ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
12# Create the PsDocument instance from the stream
13document = PsDocument(ps_stream)
14
15try:
16 # Get XMP metadata. If EPS file doesn't contain any XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
17 xmp = document.get_xmp_metadata()
18
19 #Change XMP metadata values
20
21 # Add another title. It will be added at the end of array by default.
22 xmp.add_array_item("dc:title", XmpValue("NewTitle"))
23
24 # Add one more creator. It will be added in the array by an index (0).
25 xmp.add_array_item("dc:creator", 0, XmpValue("NewCreator"))
26
27 # Save the EPS file with changed XMP metadata
28
29 # Create an ouput stream
30 with open(data_dir + "add_array_items_output.eps", "wb") as out_ps_stream:
31 # Save the EPS file
32 document.save(out_ps_stream)
33
34finally:
35 ps_stream.close()
You can download examples and data files from GitHub.