Adicionar namespace XML nos metadados XMP do EPS |Python

Para adicionar um namespace XML aos metadados XMP de um ficheiro EPS, é necessário executar 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 valores dos comentários dos metadados PS e depois devolvido a si.
  4. Agora pode adicionar um novo namespace XML aos metadados.
  5. Inicialize um fluxo de saída para o ficheiro EPS de saída.
  6. Guarde o ficheiro EPS com os metadados XMP atualizados.


O exemplo de código seguinte demonstra como adicionar um namespace XML aos metadados XMP num ficheiro EPS utilizando Python:

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
 3# Initialize an EPS file input stream
 4ps_stream = open(data_dir + "add_simple_props_input.eps", "rb",)
 5# Create a PsDocument instance from stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # Get XMP metadata. If EPS file doesn't contain any XMP metadata we get a new one filled with values from PS metadata comments (%%Creator, %%CreateDate, %%Title etc)
10    xmp = document.get_xmp_metadata()
11    
12    #Change XMP metadata values
13    
14    # Add a new XML namespace "tmp".
15    xmp.register_namespace_uri("tmp", "http://www.some.org/schema/tmp#")
16    
17    # Add a new string property in new namespace.
18    xmp.add("tmp:newKey", XmpValue("NewValue"))
19    
20    # Save the EPS file with the changed XMP metadata
21    
22    # Create an ouput stream
23    with open(data_dir + "add_namespace_output.eps", "wb") as out_ps_stream:
24        # Save EPS file
25        document.save(out_ps_stream)
26    
27finally:
28    ps_stream.close()

Veja como adicionar namespace XMl em metadados XMP em .NET, Java e C++.

Examine and download this ond the other examples and data files from GitHub.

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.