Aggiungere proprietà nei metadati XMP di un file EPS | Java

Per aggiungere proprietà ai metadati XMP di un file EPS, è necessario eseguire diversi passaggi:

  1. Inizializzare un flusso di input per il file EPS di input.
  2. Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
  3. Ottenere un’istanza di XmpMetadata dal PsDocument. Se il file EPS specificato non contiene metadati XMP, ne verrà creato uno nuovo, compilato con i valori dei commenti dei metadati PS e restituito.
  4. Ora è possibile aggiungere proprietà ai campi di metadati.
  5. Inizializzare un flusso di output per il file EPS di output.
  6. Salvare il file EPS con i metadati XMP modificati.


Il seguente frammento di codice mostra come aggiungere proprietà nei metadati XMP del file EPS in Java:

 1// Add simple properties in XMP metadata in EPS document.
 2
 3// Initialize EPS file input stream
 4try (FileInputStream psStream = new FileInputStream(getDataDir() + "add_simple_props_input.eps")) {
 5    // Create PsDocument instance from stream
 6    PsDocument document = new PsDocument(psStream);
 7
 8    String outputFileName = "add_xmp_simple_props_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        // Add Integer poperty
19        xmp.put("xmp:Intg1", new XmpValue(111));
20
21        // Add DateTime poperty
22        xmp.put("xmp:Date1", new XmpValue(Date.from(now.toInstant())));
23
24        // Add Double poperty
25        xmp.put("xmp:Double1", new XmpValue(111.11D));
26
27        // Add String poperty
28        xmp.put("xmp:String1", new XmpValue("ABC"));
29
30        // Save EPS file with changed XMP metadata
31
32        // Create ouput stream
33        try (FileOutputStream outPsStream = new FileOutputStream(getOutputDir() + outputFileName)) {
34            // Save EPS file
35            document.save(outPsStream);
36        }
37    } catch (IOException ex) {
38    }

Vedere l’aggiunta di proprietà nei metadati XMP in .NET e C++.

È possibile scaricare esempi e file di dati da GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.