XMPメタデータに配列項目を追加する| Python

EPS ファイルの XMP メタデータに配列項目を追加するには、次の手順に従います。

  1. 入力 EPS ファイルの入力ストリームを初期化します。
  2. 先ほど作成した入力ストリームから PsDocument のインスタンスを作成します。
  3. PsDocument から XmpMetadata のインスタンスを取得します。EPS ファイルに XMP メタデータが含まれていない場合は、新しいインスタンスが作成され、PS メタデータコメントから値が入力されて返されます。
  4. これで、配列メタデータフィールドに項目を追加できます。
  5. 出力 EPS ファイルの出力ストリームを初期化します。
  6. 更新された XMP メタデータを含む EPS ファイルを保存します。


以下は、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 + "add_simple_props_input.eps", "rb",)
 5# Create the 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    #Change XMP metadata values
13    
14    # Add another title. It will be added at the end of array by default.
15    xmp.add_array_item("dc:title", XmpValue("NewTitle"))
16    
17    # Add one more creator. It will be added in the array by an index (0).
18    xmp.add_array_item("dc:creator", 0, XmpValue("NewCreator"))
19    
20    # Save the EPS file with changed XMP metadata
21    
22    # Create an ouput stream
23    with open(data_dir + "add_array_items_output.eps", "wb") as out_ps_stream:
24        # Save the EPS file
25        document.save(out_ps_stream)
26    
27finally:
28    ps_stream.close()

.NETJava の XMP メタデータへの配列項目の追加を参照してください。 C++

サンプルとデータ ファイルは GitHub からダウンロードできます。

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.