Pythonを使用してEPSファイルからXMPメタデータを取得する

EPSファイルからXMPメタデータを抽出するには、いくつかの手順が必要です。

  1. 入力EPSファイル用の入力ストリームを初期化します。
  2. 先ほど作成した入力ストリームから PsDocumentのインスタンスを作成します。
  3. PsDocumentから XmpMetadataのインスタンスを取得します。EPSファイルにXMPメタデータが含まれていない場合は、新しいインスタンスが作成され、PSメタデータコメントから値が入力されて返されます。
  4. これで、メタデータフィールドの値にアクセスして表示できるようになります。


以下は、PythonでEPSファイルからXMPメタデータを抽出する方法を示すコードスニペットです。

 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()

.NETJavaC++ での XMP メタデータの抽出を参照してください。

すべての例とデータ ファイルは GitHub から確認およびダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.