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:
1from aspose.page.eps import *
2from aspose.page.eps.xmp import *
3from datetime import datetime
4from util import Util
5###############################################
6###### Class and Method declaration here ######
7###############################################
8
9# The path to the documents directory.
10data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
11# Initialize a EPS file input stream
12ps_stream = open(data_dir + "get_input.eps", "rb",)
13# Create PsDocument instance from stream
14document = PsDocument(ps_stream)
15
16try:
17 # 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)
18 xmp = document.get_xmp_metadata()
19
20 #Change the XMP metadata values
21
22 # Change ModifyDate value
23 now = datetime.utcnow()
24 #xmp["xmp:ModifyDate"] = now
25 xmp.add("xmp:ModifyDate", now)
26
27 # Change Creator value
28 value = XmpValue("Aspose.Page")
29 xmp.add("dc:creator", value)
30
31 # Change Title value
32 value = XmpValue("(PAGEJAVA-29.eps)")
33 xmp.add("dc:title", value)
34
35 # Save EPS file with changed XMP metadata
36
37 # Create an ouput stream
38 with open(data_dir + "change_values_output.eps", "wb") as out_ps_stream:
39 # Save EPS file
40 document.save(out_ps_stream)
41
42finally:
43 ps_stream.close()
You can download examples and data files from GitHub.