Add properties in XMP metadata of EPS | Python
To add properties to the XMP metadata of an EPS file, you’ll need to follow these 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 add properties to the metadata fields.
- Initialize an output stream for the output EPS file.
- Save the EPS file with the updated XMP metadata.
Below is a code snippet demonstrating how to add properties to the XMP metadata of an EPS file using 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 an EPS file input stream
12ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
13# Create a PsDocument instance from stream
14document = PsDocument(ps_stream)
15
16try:
17 # 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)
18 xmp = document.get_xmp_metadata()
19
20 #Change the XMP metadata values
21
22
23 now = datetime.utcnow()
24
25 # Add an Integer poperty
26 xmp.add("xmp:Intg1", XmpValue(111))
27
28 # Add a DateTime poperty
29 xmp.add("xmp:Date1", XmpValue(now))
30
31 # Add a Double poperty
32 xmp.add("xmp:Double1", XmpValue(111.11))
33
34 # Add a String poperty
35 xmp.add("xmp:String1", XmpValue("ABC"))
36
37 # Save the EPS file with the changed XMP metadata
38
39 # Create an ouput stream
40 with open(data_dir + "add_simple_props_output.eps", "wb") as out_ps_stream:
41 # Save the EPS file
42 document.save(out_ps_stream)
43
44finally:
45 ps_stream.close()
You can download examples and data files from GitHub.