Get XMP metadata from EPS file using Java

In order to extract XMP metadata from 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 view values of metadata fileds.


The following code snippet shows how to extract XMP metadata from EPS file in Java:

 1// Get XMP metadata from EPS document.
 2
 3// Create PsDocument instance from file
 4PsDocument document = new PsDocument(getDataDir() + "get_input.eps");
 5
 6// 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)
 7XmpMetadata xmp = document.getXmpMetadata();
 8
 9// Get "CreatorTool" value
10if (xmp.containsKey("xmp:CreatorTool"))
11    System.out.println("CreatorTool: " + xmp.get("xmp:CreatorTool").toStringValue());
12
13// Get "CreateDate" value
14if (xmp.containsKey("xmp:CreateDate"))
15    System.out.println("CreateDate: " + xmp.get("xmp:CreateDate").toStringValue());
16
17// Get a width of a thumbnail image if exists
18if (xmp.containsKey("xmp:Thumbnails") && xmp.get("xmp:Thumbnails").isArray()) {
19    XmpValue val = xmp.get("xmp:Thumbnails").toArray()[0];
20    if (val.isNamedValues() && val.toDictionary().containsKey("xmpGImg:width"))
21        System.out.println("Thumbnail Width: " + val.toDictionary().get("xmpGImg:width").toInteger());
22}
23
24// Get "format" value
25if (xmp.containsKey("dc:format"))
26    System.out.println("Format: " + xmp.get("dc:format").toStringValue());
27
28// Get "DocumentID" value
29if (xmp.containsKey("xmpMM:DocumentID"))
30    System.out.println("DocumentID: " + xmp.get("xmpMM:DocumentID").toStringValue());

See extracting 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.