Add named value in XMP metadata of EPS | Python

To add a named value to the XMP metadata of an EPS file, 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 does not 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 the named value to the structure 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 a named value to the XMP metadata in an EPS file in 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_named_value_input.eps", "rb",)
12# Create PsDocument instance from stream
13document = PsDocument(ps_stream)
14
15try:
16    # Get XMP metadata. If the EPS file doesn't contain 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 XMP metadata values
20    
21    # Add a named value to "xmpTPg:MaxPageSize" structure.
22    xmp.add_named_value("xmpTPg:MaxPageSize", "stDim:newKey", XmpValue("NewValue"))
23    
24    # Save the EPS file with changed XMP metadata
25    
26    # Create an ouput stream
27    with open(data_dir + "add_named_value_output.eps", "wb") as out_ps_stream:
28        # Save EPS file
29        document.save(out_ps_stream)
30    
31finally:
32    ps_stream.close()

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

You can download all the examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.