Obter metadados XMP de um ficheiro EPS utilizando Java

Para extrair metadados XMP de 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.


O seguinte excerto de código mostra como extrair metadados XMP de um ficheiro EPS em 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 + "xmp1.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    // Get "CreatorTool" value
18    if (xmp.containsKey("xmp:CreatorTool"))
19        System.out.println("CreatorTool: " + xmp.get("xmp:CreatorTool").toStringValue());
20    
21    // Get "CreateDate" value
22    if (xmp.containsKey("xmp:CreateDate"))
23        System.out.println("CreateDate: " + xmp.get("xmp:CreateDate").toStringValue());
24
25    // Get a width of a thumbnail image if exists
26    if (xmp.containsKey("xmp:Thumbnails") && xmp.get("xmp:Thumbnails").isArray()) {
27        XmpValue val = xmp.get("xmp:Thumbnails").toArray()[0];
28        if (val.isNamedValues() && val.toNamedValues().containsKey("xmpGImg:width"))
29            System.out.println("Thumbnail Width: " + val.toNamedValues().get("xmpGImg:width").toInteger());
30    }
31
32    // Get "format" value
33    if (xmp.containsKey("dc:format"))
34        System.out.println("Format: " + xmp.get("dc:format").toStringValue());
35
36    // Get "DocumentID" value
37    if (xmp.containsKey("xmpMM:DocumentID"))
38        System.out.println("DocumentID: " + xmp.get("xmpMM:DocumentID").toStringValue());
39
40} finally {
41    // close input EPS stream
42	psStream.close();
43}

Ver extração de 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.