Change simple values in XMP EPS metadata |Python
In order to change simple values 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 values of 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 simple values in XMP metadata of EPS file in Python:
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()
You can download examples and data files from GitHub.