Ottieni metadati XMP da file EPS usando Python
Per estrarre i metadati XMP da un file EPS, è necessario eseguire diversi passaggi:
- Inizializzare un flusso di input per il file EPS di input.
- Creare un’istanza di PsDocument dal flusso di input creato in precedenza.
- 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, che verrà poi restituito all’utente.
- Ora è possibile accedere e visualizzare i valori dei campi dei metadati.
Di seguito è riportato un frammento di codice che mostra come estrarre i metadati XMP da un file EPS in Python:
1# The path to the documents directory.
2data_dir = Util.get_data_dir_working_with_xmp_metadata_in_eps()
3# Initialize the EPS file input stream
4ps_stream = open(data_dir + "get_input.eps", "rb",)
5# Create PsDocument instance from the stream
6document = PsDocument(ps_stream)
7
8try:
9 # Get XMP metadata. If EPS file doesn't contain any 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 # Get "CreatorTool" value
13 if xmp.contains("xmp:CreatorTool"):
14 print("CreatorTool: " + xmp.get_value("xmp:CreatorTool").to_string_value())
15
16 # Get "CreateDate" value
17 if xmp.contains("xmp:CreateDate"):
18 print("CreateDate: " + xmp.get_value("xmp:CreateDate").to_string_value())
19
20 # Get "format" value
21 if xmp.contains("dc:format"):
22 print("Format: " + xmp.get_value("dc:format").to_string_value())
23
24 # Get "DocumentID" value
25 if xmp.contains("xmpMM:DocumentID"):
26 print("DocumentID: " + xmp.get_value("xmpMM:DocumentID").to_string_value())
27
28finally:
29 ps_stream.close()
You can examine and download all the examples and data files from GitHub.