Aggiungi namespace XML nei metadati XMP di EPS | Python

Per aggiungere uno spazio dei nomi XML ai metadati XMP di un file EPS, è necessario eseguire i seguenti passaggi:

  1. Inizializzare un flusso di input per il file EPS di input.
  2. Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
  3. Ottenere un’istanza di XmpMetadata dal PsDocument. Se il file EPS non contiene metadati XMP, ne verrà creato uno nuovo, popolato con i valori dei commenti dei metadati PS e restituito all’utente.
  4. Ora è possibile aggiungere un nuovo spazio dei nomi XML ai metadati.
  5. Inizializzare un flusso di output per il file EPS di output.
  6. Salvare il file EPS con i metadati XMP aggiornati.


Il seguente esempio di codice mostra come aggiungere uno spazio dei nomi XML ai metadati XMP in un file EPS utilizzando 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()

Vedere l’aggiunta dello spazio dei nomi XML nei metadati XMP in .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.