Agregue metadatos XMP a un archivo EPS usando Java

Para agregar metadatos XMP a 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.
  5. Inicialice un flujo de salida para el archivo EPS de salida.
  6. Guarde el archivo EPS con nuevos metadatos XMP.

El siguiente fragmento de código muestra cómo agregar metadatos XMP a un archivo EPS en Java:

 1// Add XMP metadata to EPS document.
 2
 3// Initialize EPS file input stream
 4try (FileInputStream psStream = new FileInputStream(getDataDir() + "add_input.eps")) {
 5    // Create PsDocument instance from stream. Given EPS file doesn't contain XMP metadata, but usual metadata does contain.
 6    PsDocument document = new PsDocument(psStream);
 7
 8    String outputFileName = "add_xmp_metadata_out.eps";
 9
10    XmpMetadata xmp = null;
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        xmp = document.getXmpMetadata();
15
16        // Check metadata values extracted from PS metadata comments and set up in new XMP metadata
17
18        // Get "CreatorTool" value
19        if (xmp.containsKey("xmp:CreatorTool"))
20            System.out.println("CreatorTool: " + xmp.get("xmp:CreatorTool").toStringValue());
21
22        // Get "CreateDate" value
23        if (xmp.containsKey("xmp:CreateDate"))
24            System.out.println("CreateDate: " + xmp.get("xmp:CreateDate").toStringValue());
25
26        // Get "format" value
27        if (xmp.containsKey("dc:format"))
28            System.out.println("Format: " + xmp.get("dc:format").toStringValue());
29
30        // Get "title" value
31        if (xmp.containsKey("dc:title"))
32            System.out.println("Title: " + xmp.get("dc:title").toArray()[0].toStringValue());
33
34        // Get "creator" value
35        if (xmp.containsKey("dc:creator"))
36            System.out.println("Creator: " + xmp.get("dc:creator").toArray()[0].toStringValue());
37
38        // Get "MetadataDate" value
39        if (xmp.containsKey("xmp:MetadataDate"))
40            System.out.println("MetadataDate: " + xmp.get("xmp:MetadataDate").toStringValue());
41
42        // Update MetadataDate value                
43        Date metadataDate = xmp.get("xmp:MetadataDate").toDateTime();
44
45        // Save EPS file with new XMP metadata
46
47        // Create ouput stream
48        try (FileOutputStream outPsStream = new FileOutputStream(getOutputDir() + outputFileName)) {
49            // Save EPS file
50            document.save(outPsStream);
51        }
52    } catch (IOException ex) {
53    }

Consulte cómo agregar 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.