Change simple values in XMP EPS metadata |Java

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


The following code snippet shows how to change simple values in XMP metadata of EPS file in Java:

 1// Change values in XMP metadata in EPS document.
 2	
 3// Initialize EPS file input stream
 4try (FileInputStream psStream = new FileInputStream(getDataDir() + "get_input.eps")) {
 5    // Create PsDocument instance from stream
 6    PsDocument document = new PsDocument(psStream);
 7	
 8    String outputFileName = "change_values_out.eps";
 9    ZoneId systemZone = ZoneId.systemDefault();
10    OffsetDateTime now = LocalDateTime.now().atZone(systemZone).toOffsetDateTime();
11	
12    try {
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        //Change XMP metadata values
17	
18        // Change ModifyDate value
19        xmp.put("xmp:ModifyDate", new XmpValue(Date.from(now.toInstant())));
20	
21        // Change Creator value
22        XmpValue value = new XmpValue("Aspose.Page");
23        xmp.put("dc:creator", value);
24	
25        // Change Title value
26        value = new XmpValue("(change_values.eps)");
27        xmp.put("dc:title", value);
28	
29        // Save EPS file with changed XMP metadata
30	
31        // Create ouput stream
32        try (FileOutputStream outPsStream = new FileOutputStream(getOutputDir() + outputFileName)) {
33            // Save EPS file
34            document.save(outPsStream);
35        }
36    } catch (IOException ex) {
37    }

See changing simple values 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.