EPSファイルの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 a EPS file input stream
 4ps_stream = open(data_dir + "add_named_value_input.eps", "rb",)
 5# Create a PsDocument instance from the stream
 6document = PsDocument(ps_stream)
 7
 8try:
 9    # Get XMP metadata. If the EPS file doesn't contain 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 the XMP metadata values
13    
14    # Change the named value "stDim:unit" in "xmpTPg:MaxPageSize" structure.
15    xmp.set_named_value("xmpTPg:MaxPageSize", "stDim:unit", XmpValue("Inches"))
16    
17    # Add the named value "stDim:newKey" in "xmpTPg:MaxPageSize" structure.
18    xmp.set_named_value("xmpTPg:MaxPageSize", "stDim:newKey", XmpValue("NewValue"))
19    
20    # Save the EPS file with changed XMP metadata
21    
22    # Create an ouput stream
23    with open(data_dir + "change_named_value_output.eps", "wb") as out_ps_stream:
24        # Save EPS file
25        document.save(out_ps_stream)
26    
27finally:
28    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.