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:

  1. Initialize an input stream for the input EPS file.
  2. Create an instance of PsDocument from the previously created input stream.
  3. 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.
  4. Now you can add properties to the metadata fields.
  5. Initialize an output stream for the output EPS file.
  6. 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:

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
 3# Initialize an EPS file input stream
 4ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
 5# Create a PsDocument instance from stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # 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)
10    xmp = document.get_xmp_metadata()
11    
12    #Change the XMP metadata values
13    
14    
15    now = datetime.utcnow()
16    
17    # Add an Integer poperty
18    xmp.add("xmp:Intg1", XmpValue(111))
19    
20    # Add a DateTime poperty
21    xmp.add("xmp:Date1", XmpValue(now))
22    
23    # Add a Double poperty
24    xmp.add("xmp:Double1", XmpValue(111.11))
25    
26    # Add a String poperty
27    xmp.add("xmp:String1", XmpValue("ABC"))
28    
29    # Save the EPS file with the changed XMP metadata
30    
31    # Create an ouput stream
32    with open(data_dir + "add_simple_props_output.eps", "wb") as out_ps_stream:
33        # Save the EPS file
34        document.save(out_ps_stream)
35    
36finally:
37    ps_stream.close()

See adding properties in XMP metadata in .NET, Java and C++.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.