处理 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 文档文本的处理方法。


结果

Add Text

使用编码字符串添加文本

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.