Adicionar metadados XMP a um ficheiro EPS utilizando Java

Para adicionar metadados XMP a um ficheiro EPS, é necessário seguir vários passos:

  1. Inicializar um fluxo de entrada para o ficheiro EPS de entrada.
  2. Criar uma instância de PsDocument a partir do fluxo de entrada criado anteriormente.
  3. Obter uma instância de XmpMetadata a partir do PsDocument. Se o ficheiro EPS fornecido não contiver metadados XMP, um novo será criado, preenchido com os valores dos comentários de metadados PS e devolvido a si.
  4. Agora pode visualizar os valores dos campos de metadados.
  5. Inicializar um fluxo de saída para o ficheiro EPS de saída.
  6. Guardar o ficheiro EPS com os novos metadados XMP.


O seguinte excerto de código mostra como adicionar metadados XMP a um ficheiro EPS em 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    }

Veja como adicionar metadados XMP em .NET e C++.

Pode descarregar exemplos e ficheiros de dados do GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.