Change array items in XMP metadata of EPS| Python
In order to change array items in XMP metadata of EPS file you will need to take several steps:
- Initialize an input stream for the input EPS file.
- Create an instance of PsDocument from the previously created input stream.
- Get an instance of XmpMetadata from the PsDocument. If the EPS file doesn’t contain XMP metadata, a new one will be created and populated with values from PS metadata comments, then returned to you.
- Now you can change items of array metadata fileds.
- Initialize an output stream for the output EPS file.
- Save EPS file with new XMP metadata.
Here is a code snippet that shows how to change array items in XMP metadata of an EPS file using 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 an EPS file input stream
11ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
12# Create a PsDocument instance from stream
13document = PsDocument(ps_stream)
14
15try:
16 # 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)
17 xmp = document.get_xmp_metadata()
18
19 #Change the XMP metadata values
20
21 # Change the title item at index 0
22 xmp.set_array_item("dc:title", 0, XmpValue("NewTitle"))
23
24 # Change the creator item at index 0
25 xmp.set_array_item("dc:creator", 0, XmpValue("NewCreator"))
26
27 # Save the EPS file with the changed XMP metadata
28
29 # Create an ouput stream
30 with open(data_dir + "change_array_items_output.eps", "wb") as out_ps_stream:
31 # Save EPS file
32 document.save(out_ps_stream)
33
34finally:
35 ps_stream.close()
You can download examples and data files from GitHub.