Obtenga metadatos XMP de un archivo EPS usando Java

Para extraer metadatos XMP de un archivo EPS es necesario seguir varios pasos:

  1. Inicialice un flujo de entrada para el archivo EPS de entrada.
  2. Cree una instancia de PsDocument a partir del flujo de entrada creado anteriormente.
  3. Obtenga una instancia de XmpMetadata del PsDocument. Si el archivo EPS dado no contiene metadatos XMP, el nuevo se creará, se completará con valores de los comentarios de metadatos de PS y se le devolverá.
  4. Ahora puedes ver los valores de los campos de metadatos.

El siguiente fragmento de código muestra cómo extraer metadatos XMP de un archivo EPS en 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());

Consulte la extracción de metadatos XMP en .NET y C++.

Puede descargar ejemplos y archivos de datos desde GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.