Agregar elementos de matriz en metadatos XMP de EPS| Java
Para agregar elementos de matriz en metadatos XMP de un archivo EPS, es necesario seguir varios pasos:
- Inicialice un flujo de entrada para el archivo EPS de entrada.
- Cree una instancia de PsDocument a partir del flujo de entrada creado anteriormente.
- 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á.
- Ahora puede agregar elementos a los campos de metadatos de la matriz.
- Inicialice un flujo de salida para el archivo EPS de salida.
- Guarde el archivo EPS con los metadatos XMP modificados.
El siguiente fragmento de código muestra cómo agregar elementos de matriz en metadatos XMP en un archivo EPS en Java:
1// Add array items 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_array_items_out.eps"; 9 10 try { 11 // 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) 12 XmpMetadata xmp = document.getXmpMetadata(); 13 14 //Change XMP metadata values 15 16 // Add one more title. I will be added at the end of array by default. 17 xmp.addArrayItem("dc:title", new XmpValue("NewTitle")); 18 19 // Add one more creator. It will be added in the array by an index (0). 20 xmp.addArrayItem("dc:creator", 0, new XmpValue("NewCreator")); 21 22 // Save EPS file with changed XMP metadata 23 24 // Create ouput stream 25 try (FileOutputStream outPsStream = new FileOutputStream(getOutputDir() + outputFileName)) { 26 // Save EPS file 27 document.save(outPsStream); 28 } 29 } catch (IOException ex) { 30 }Puede descargar ejemplos y archivos de datos desde GitHub.