处理 XPS 文件中的文本 | Python
Contents
[
Hide
Show
]您将在这里找到代码,了解如何使用 Python 处理 XPS 文件中的文本。
向 XPS 文档添加文本
Aspose.Page for Python via .NET 提供了 XpsGlyphs 类,使您能够将文本插入 XPS 文档。为此,您必须指定 API 提供的画笔。在下面的示例中,我们使用 XpsSolidColorBrush,然后保存 XpsDocument 类的对象。以下代码片段演示了向 XPS 文档添加文本的完整功能:
1from aspose.page.xps import *
2import aspose.pydrawing
3from util import Util
4# The path to the documents directory.
5data_dir = Util.get_data_dir_working_with_text()
6# Create a new XPS Document
7doc = XpsDocument()
8# Create a brush
9text_fill = doc.create_solid_color_brush(aspose.pydrawing.Color.black)
10# Add a glyph to the document
11glyphs = doc.add_glyphs("Arial", 12, aspose.pydrawing.FontStyle.REGULAR, 300, 450, "Hello World!")
12glyphs.fill = text_fill
13# Save the resultant XPS document
14doc.save(data_dir + "AddText_out.xps")结果

使用编码字符串添加文本
Aspose.Page for Python 解决方案提供了 XpsGlyphs 类,使您能够使用编码字符串向 XPS 文档添加文本。您可以使用 XpsGlyphs 类的 set_bidi_level() 属性指定画笔。以下代码片段演示了使用编码字符串添加文本的完整功能:
1from aspose.page.xps import *
2import aspose.pydrawing
3from util import Util
4# The path to the documents directory.
5data_dir = Util.get_data_dir_working_with_text()
6# Create a new XPS Document
7doc = XpsDocument()
8# Add Text
9text_fill = doc.create_solid_color_brush(aspose.pydrawing.Color.black)
10glyphs = doc.add_glyphs("Arial", 20, aspose.pydrawing.FontStyle.REGULAR, 400, 200, "TEN. rof SPX.esopsA")
11glyphs.bidi_level = 1
12glyphs.fill = text_fill
13# Save the resultant XPS document
14doc.save(data_dir + "AddTextRTL_out.xps")结果

您可以从 GitHub下载示例和数据文件。