XPSファイル内のテキスト操作 | Python

ここでは、Python を使用して XPS ファイル内のテキストを操作する方法を説明するコードを紹介します。

XPS ドキュメントへのテキストの追加

Aspose.Page for Python via .NET は XpsGlyphs クラス を提供しており、これを使用して XPS ドキュメントにテキストを挿入できます。これを行うには、API が提供するブラシを指定する必要があります。以下の例では、XpsSolidColorBrush を使用し、XpsDocument クラスのオブジェクトを保存します。次のコード スニペットは、XPS ドキュメントにテキストを追加する機能のすべてを示しています。

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_text()
 3# Create a new XPS Document
 4doc = XpsDocument()
 5# Create a brush 
 6text_fill = doc.create_solid_color_brush(aspose.pydrawing.Color.black)
 7# Add a glyph to the document
 8glyphs = doc.add_glyphs("Arial", 12, aspose.pydrawing.FontStyle.REGULAR, 300, 450, "Hello World!")
 9glyphs.fill = text_fill
10# Save the resultant XPS document
11doc.save(data_dir + "AddText_out.xps")

.NETJavaC++ での XPS ドキュメント内のテキストの操作を参照してください。


結果

テキストの追加

エンコーディング文字列を使用したテキストの追加

Aspose.Page for Python ソリューションは XpsGlyphs クラス を提供しており、これを使用すると、エンコーディング文字列を使用して XPS ドキュメントにテキストを追加できます。XpsGlyphs クラスの set_bidi_level() プロパティを使用してブラシを指定できます。次のコード スニペットは、エンコーディング文字列を使用してテキストを追加する機能のすべてを示しています。

 1# The path to the documents directory.
 2data_dir = Util.get_data_dir_working_with_text()
 3# Create a new XPS Document
 4doc = XpsDocument()
 5# Add Text
 6text_fill = doc.create_solid_color_brush(aspose.pydrawing.Color.black)
 7glyphs = doc.add_glyphs("Arial", 20, aspose.pydrawing.FontStyle.REGULAR, 400, 200, "TEN. rof SPX.esopsA")
 8glyphs.bidi_level = 1
 9glyphs.fill = text_fill
10# Save the resultant XPS document
11doc.save(data_dir + "AddTextRTL_out.xps")

.NETJavaC++ での XPS ドキュメント内のテキストの操作を参照してください。


結果

右から左へのテキストの追加

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

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.