Add XML namespace in XMP metadata of EPS |Java

In order to add XML namespace in XMP metadata of EPS file it is necessary to do several steps:

  1. Initialize an input stream for input EPS file.
  2. Create an instance of PsDocument from created earlier input stream.
  3. Get an instance of XmpMetadata from the PsDocument. If given EPS file doesn’t contain XMP metadata the new one will be created, filled in with values from PS metadata comments and returned to you.
  4. Now you can add new XML namespace to metadata.
  5. Initialize an output stream for output EPS file.
  6. Save EPS file with changed XMP metadata.


The following code snippet shows how to add XML namespace in XMP metadata in EPS file in Java:

 1// Add namespace in XMP metadata in EPS document.
 2	
 3// Initialize EPS file input stream
 4try (FileInputStream psStream = new FileInputStream(getDataDir() + "add_simple_props_input.eps")) {
 5    // Create PsDocument instance from stream
 6    PsDocument document = new PsDocument(psStream);
 7	
 8    String outputFileName = "add_xmp_namespace_out.eps";
 9	
10    try {
11        // Get XMP metadata. If EPS file doesn't contain XMP metadata we get new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
12        XmpMetadata xmp = document.getXmpMetadata();
13	
14        //Change XMP metadata values
15	
16        // Add new XML namespace "tmp".
17        xmp.registerNamespaceURI("tmp", "http://www.some.org/schema/tmp#");
18	
19        // Add new string property in new namespace.
20        xmp.put("tmp:newKey", new XmpValue("NewValue"));
21	
22        // Save EPS file with changed XMP metadata
23	
24        // Create ouput stream
25        try (FileOutputStream outPsStream = new FileOutputStream(getOutputDir() + outputFileName)) {
26            // Save EPS file
27            document.save(outPsStream);
28        }
29    } catch (IOException ex) {
30    }

See adding XMl namespace in XMP metadata in .NET and C++.

You can download 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.