Get XMP metadata from EPS file using Python

To extract XMP metadata from an EPS file, several steps need to be taken:

  1. Initialize an input stream for input EPS file.
  2. Create an instance of PsDocument from the previously created input stream.
  3. Obtain 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. You can now access and view the values of the metadata fields.


Below is a code snippet demonstrating how to extract XMP metadata from an 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 the EPS file input stream
 4ps_stream = open(data_dir + "get_input.eps", "rb",)
 5# Create PsDocument instance from the stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # Get XMP metadata. If EPS file doesn't contain any XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
10    xmp = document.get_xmp_metadata()
11    
12    # Get "CreatorTool" value
13    if xmp.contains("xmp:CreatorTool"):
14        print("CreatorTool: " + xmp.get_value("xmp:CreatorTool").to_string_value())
15    
16    # Get "CreateDate" value
17    if xmp.contains("xmp:CreateDate"):
18        print("CreateDate: " + xmp.get_value("xmp:CreateDate").to_string_value())
19    
20    # Get "format" value
21    if xmp.contains("dc:format"):
22        print("Format: " + xmp.get_value("dc:format").to_string_value())
23    
24    # Get "DocumentID" value
25    if xmp.contains("xmpMM:DocumentID"):
26        print("DocumentID: " + xmp.get_value("xmpMM:DocumentID").to_string_value())
27    
28finally:
29    ps_stream.close()

See extracting XMP metadata in .NET, Java and C++.

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

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.