Add XML namespace in XMP metadata of EPS |Python
To add an XML namespace to the XMP metadata of an EPS file, you need to perform the following 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 does not 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 a new XML namespace to the metadata.
- Initialize an output stream for the output EPS file.
- Save the EPS file with the updated XMP metadata.
The following code example demonstrates how to add an XML namespace to the XMP metadata in an EPS file using 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_simple_props_input.eps", "rb",)
12# Create a PsDocument instance from stream
13document = PsDocument(ps_stream)
14
15try:
16 # 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)
17 xmp = document.get_xmp_metadata()
18
19 #Change XMP metadata values
20
21 # Add a new XML namespace "tmp".
22 xmp.register_namespace_uri("tmp", "http://www.some.org/schema/tmp#")
23
24 # Add a new string property in new namespace.
25 xmp.add("tmp:newKey", XmpValue("NewValue"))
26
27 # Save the EPS file with the changed XMP metadata
28
29 # Create an ouput stream
30 with open(data_dir + "add_namespace_output.eps", "wb") as out_ps_stream:
31 # Save EPS file
32 document.save(out_ps_stream)
33
34finally:
35 ps_stream.close()
Examine and download this ond the other examples and data files from GitHub.