Aggiungere elementi array nei metadati XMP di EPS | Java
Per aggiungere elementi array nei metadati XMP di un file EPS, è necessario eseguire diversi passaggi:
- Inizializzare un flusso di input per il file EPS di input.
- Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
- 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.
- Ora è possibile aggiungere elementi ai campi dei metadati array.
- Inizializzare un flusso di output per il file EPS di output.
- Salvare il file EPS con i metadati XMP modificati.
Il seguente frammento di codice mostra come aggiungere elementi array nei metadati XMP nel file EPS 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.
6String dataDir = Utils.getDataDir();
7
8// Initialize input EPS file stream
9FileInputStream psStream = new FileInputStream(dataDir + "xmp3.eps");
10
11PsDocument document = new PsDocument(psStream);
12
13try {
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 // Add one more "dc:title" array item
18 xmp.addArrayItem("dc:title", new XmpValue("NewTitle"));
19
20 // Add one more "dc:creator" array item
21 xmp.addArrayItem("dc:creator", new XmpValue("NewCreator"));
22
23
24 // Initialize output EPS file stream
25 FileOutputStream outPsStream = new FileOutputStream(dataDir + "xmp3_changed.eps");
26
27 // Save document with changed XMP metadata
28 try {
29 document.save(outPsStream);
30 } finally {
31 outPsStream.close();
32 }
33
34} finally {
35 // close input EPS stream
36 psStream.close();
37}
È possibile scaricare esempi e file di dati da GitHub.