EPSのXMPメタデータにXML名前空間を追加する |Python
EPS ファイルの XMP メタデータに XML 名前空間を追加するには、以下の手順を実行する必要があります。
- 入力 EPS ファイルの入力ストリームを初期化します。
- 先ほど作成した入力ストリームから PsDocument のインスタンスを作成します。
- PsDocument から XmpMetadata のインスタンスを取得します。EPS ファイルに XMP メタデータが含まれていない場合は、新しい XMP メタデータが作成され、PS メタデータコメントから値が入力されて返されます。
- これで、メタデータに新しい XML 名前空間を追加できます。
- 出力 EPS ファイルの出力ストリームを初期化します。
- 更新された XMP メタデータを含む EPS ファイルを保存します。
次のコード例は、Python を使用して EPS ファイル内の XMP メタデータに XML 名前空間を追加する方法を示しています。
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()
これとその他の例およびデータ ファイルを GitHub から調べてダウンロードしてください。