Change named value in XMP metadata of EPS|Java

In order to change named value 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 named value of structure 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 named value in XMP metadata in EPS file in Java:

 1// Set license
 2new License().setLicense(BaseExamplesTest.LICENSE_PATH);
 3
 4// The path to the documents directory.
 5String dataDir = Utils.getDataDir();
 6
 7// Initialize input EPS file stream
 8FileInputStream psStream = new FileInputStream(dataDir + "xmp4.eps");
 9
10PsDocument document = new PsDocument(psStream);
11
12try {
13    // 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)
14    XmpMetadata xmp = document.getXmpMetadata();
15
16    // Set new string value "Inches" for named value "stDim:unit" of structure "xmpTPg:MaxPageSize" 
17    xmp.setNamedValue("xmpTPg:MaxPageSize", "stDim:unit", new XmpValue("Inches"));
18    
19    
20    // Initialize output EPS file stream
21    FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp4_changed.eps");
22    
23    // Save document with changed XMP metadata
24		try {			
25			document.save(outPsStream);
26		} finally {
27			outPsStream.close();
28		}
29
30} finally {
31    // close input EPS stream
32		psStream.close();
33}

See changing named value 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.