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.


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

 1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
 2// Set license
 3new License().setLicense(BaseExamplesTest.LICENSE_PATH);
 4
 5  // The path to the documents directory.
 6  String dataDir = Utils.getDataDir();
 7  
 8  // Initialize input EPS file stream
 9  FileInputStream psStream = new FileInputStream(dataDir + "xmp1.eps");
10
11  PsDocument document = new PsDocument(psStream);
12
13  try {
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();
16
17      // Change "ModifyDate" value
18      TimeZone.setDefault( TimeZone.getTimeZone("UTC"));
19      Date now = new Date();
20      xmp.put("xmp:ModifyDate", new XmpValue(now));
21      
22      // Change "creator" value
23      XmpValue value = new XmpValue("Aspose.Page");
24      xmp.put("dc:creator", value);
25
26      // Change "title" value
27      value = new XmpValue("(PAGEJAVA-29.eps)");
28      xmp.put("dc:title", value);
29      
30      
31      // Initialize output EPS file stream
32      FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp1_changed.eps");
33      
34      // Save document with changed XMP metadata
35			try {			
36				document.save(outPsStream);
37			} finally {
38				outPsStream.close();
39			}
40
41} finally {
42    // close input EPS stream
43		psStream.close();
44}

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