Get XMP metadata from EPS file using Python
To extract XMP metadata from an EPS file, several steps need to be taken:
- Initialize an input stream for input EPS file.
- Create an instance of PsDocument from the previously created input stream.
- 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.
- 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:
1from aspose.page.eps import *
2from util import Util
3###############################################
4###### Class and Method declaration here ######
5###############################################
6
7# The path to the documents directory.
8data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
9# Initialize the EPS file input stream
10ps_stream = open(data_dir + "get_input.eps", "rb",)
11# Create PsDocument instance from the stream
12document = PsDocument(ps_stream)
13
14try:
15 # 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)
16 xmp = document.get_xmp_metadata()
17
18 # Get "CreatorTool" value
19 if xmp.contains("xmp:CreatorTool"):
20 print("CreatorTool: " + xmp.get_value("xmp:CreatorTool").to_string_value())
21
22 # Get "CreateDate" value
23 if xmp.contains("xmp:CreateDate"):
24 print("CreateDate: " + xmp.get_value("xmp:CreateDate").to_string_value())
25
26 # Get "format" value
27 if xmp.contains("dc:format"):
28 print("Format: " + xmp.get_value("dc:format").to_string_value())
29
30 # Get "DocumentID" value
31 if xmp.contains("xmpMM:DocumentID"):
32 print("DocumentID: " + xmp.get_value("xmpMM:DocumentID").to_string_value())
33
34finally:
35 ps_stream.close()
You can examine and download all the examples and data files from GitHub.