Adicionar metadados XMP a um ficheiro EPS utilizando Python

Para adicionar metadados XMP a um ficheiro EPS utilizando Python, siga os seguintes passos:

  1. Inicialize um fluxo de entrada para o ficheiro EPS de entrada.
  2. Crie uma instância de PsDocument a partir do fluxo de entrada criado anteriormente.
  3. Obtenha uma instância de XmpMetadata a partir do PsDocument. Se o ficheiro EPS não contiver metadados XMP, será criado um novo e preenchido com os valores dos comentários dos metadados PS e, em seguida, será 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 ao ficheiro EPS em Python:

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
 3# Initialize EPS file input stream
 4ps_stream = open(data_dir + "add_input.eps", "rb",)
 5# Create PsDocument instance from stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # 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)
10    xmp = document.get_xmp_metadata()
11    
12    # Check metadata values extracted from PS metadata comments and set up in new XMP metadata
13    
14    # Get "CreatorTool" value
15    if xmp.contains("xmp:CreatorTool"):
16        print("CreatorTool: " + xmp.get_value("xmp:CreatorTool").to_string_value())
17    
18    # Get "CreateDate" value
19    if xmp.contains("xmp:CreateDate"):
20        print("CreateDate: " + xmp.get_value("xmp:CreateDate").to_string_value())
21    
22    # Get "format" value
23    if xmp.contains("dc:format"):
24        print("Format: " + xmp.get_value("dc:format").to_string_value())
25    
26    # Get "title" value
27    if xmp.contains("dc:title"):
28        print("Title: " + xmp.get_value("dc:title").to_array()[0].to_string_value())
29    
30    # Get "creator" value
31    if xmp.contains("dc:creator"):
32        print("Creator: " + xmp.get_value("dc:creator").to_array()[0].to_string_value())
33    
34    # Get "MetadataDate" value
35    if xmp.contains("xmp:MetadataDate"):
36        print("MetadataDate: " + xmp.get_value("xmp:MetadataDate").to_string_value())
37    
38    # Save EPS file with new XMP metadata
39    
40    # Create ouput stream
41    with open(data_dir + "add_output.eps", "wb") as out_ps_stream:
42        # Save EPS file
43        document.save(out_ps_stream)
44    
45finally:
46    ps_stream.close()

Veja como adicionar metadados XMP em .NET, Java 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.