Change array items in XMP metadata of EPS| Java

In order to change array items 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 change items of array metadata fileds.
  5. Initialize an output stream for output EPS file.
  6. Save EPS file with changed XMP metadata.

Following code snippet shows how to change array items in XMP metadata in EPS file in Java:

 1// For complete examples and data files, please go to
 2// Set license
 3new License().setLicense(BaseExamplesTest.LICENSE_PATH);
 5// The path to the documents directory.
 6String dataDir = Utils.getDataDir();
 8// Initialize input EPS file stream
 9FileInputStream psStream = new FileInputStream(dataDir + "xmp3.eps");
11PsDocument document = new PsDocument(psStream);
13try {
14    // 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)
15    XmpMetadata xmp = document.getXmpMetadata();
17    // Set "dc:title" array item by index 0 
18    xmp.setArrayItem("dc:title", 0, new XmpValue("NewTitle"));
20    // Set "dc:creator" array item by index 0
21    xmp.setArrayItem("dc:creator", 0, new XmpValue("NewCreator"));
24    // Initialize output EPS file stream
25    FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp3_changed.eps");
27    // Save document with changed XMP metadata
28		try {			
30		} finally {
31			outPsStream.close();
32		}
34} finally {
35    // close input EPS stream
36		psStream.close();

See changing array items in XMP metadata in .NET and C++.

You can download examples and data files from GitHub.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.