Adicionar metadados XMP a um ficheiro EPS utilizando .NET

Pode verificar a qualidade dos metadados XMP do Aspose.Page trabalhando com a aplicação web Metadados

Para adicionar metadados XMP ao 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 dos metadados PS e devolvido a si.
  4. Agora pode visualizar os valores dos campos de metadados.
  5. Inicialize um fluxo de saída para o ficheiro EPS de saída.
  6. Guarde o ficheiro EPS com os novos metadados XMP.

O seguinte excerto de código mostra como adicionar metadados XMP a um ficheiro EPS em C#:

 1// Add XMP metadata to EPS document.
 2
 3// Initialize EPS file input stream
 4System.IO.FileStream psStream = new System.IO.FileStream(DataDir + "add_input.eps", System.IO.FileMode.Open, System.IO.FileAccess.Read);
 5
 6// Create PsDocument instance from stream. Given EPS file doesn't contain XMP metadata, but usual metadata does contain.
 7PsDocument document = new PsDocument(psStream);
 8
 9string outputFileName = "add_xmp_metadata_out.eps";
10
11XmpMetadata xmp = null;            
12
13try
14{
15    // 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)
16    xmp = document.GetXmpMetadata();
17
18    // Check metadata values extracted from PS metadata comments and set up in new XMP metadata
19
20    // Get "CreatorTool" value
21    if (xmp.Contains("xmp:CreatorTool"))
22        Console.WriteLine("CreatorTool: " + xmp["xmp:CreatorTool"].ToStringValue());
23
24    // Get "CreateDate" value
25    if (xmp.Contains("xmp:CreateDate"))
26        Console.WriteLine("CreateDate: " + xmp["xmp:CreateDate"].ToStringValue());
27
28    // Get "format" value
29    if (xmp.Contains("dc:format"))
30        Console.WriteLine("Format: " + xmp["dc:format"].ToStringValue());
31
32    // Get "title" value
33    if (xmp.Contains("dc:title"))
34        Console.WriteLine("Title: " + xmp["dc:title"].ToArray()[0].ToStringValue());
35
36    // Get "creator" value
37    if (xmp.Contains("dc:creator"))
38        Console.WriteLine("Creator: " + xmp["dc:creator"].ToArray()[0].ToStringValue());
39
40    // Get "MetadataDate" value
41    if (xmp.Contains("xmp:MetadataDate"))
42        Console.WriteLine("MetadataDate: " + xmp["xmp:MetadataDate"].ToStringValue());
43
44    // Update MetadataDate value                
45    DateTime metadataDate = xmp["xmp:MetadataDate"].ToDateTime();
46
47    // Save EPS file with new XMP metadata
48
49    // Create ouput stream
50    using (System.IO.FileStream outPsStream = new System.IO.FileStream(OutputDir + outputFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))
51    {
52        // Save EPS file
53        document.Save(outPsStream);
54    }
55}
56finally
57{
58    psStream.Close();
59}

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

Avalie os metadados XMP a funcionar online na nossa aplicação Metadados.

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.