文本操作 | C++ API 解决方案

添加文本

向 XPS 文档添加文本

Aspose.Page for C++ 允许您在 C++ 应用程序中向 XPS 文档添加文本。 XpsGlyphs 类允许您通过指定所选画笔向 XPS 文档添加文本。 可以使用以下步骤将文本添加到 XPS 文档:

  1. 创建 XPSDocument 类的新实例
  2. 使用 XpsSolidColorBrush 类创建画笔
  3. 使用所需的字体信息将字形添加到文档对象
  4. 使用 XPSDocument 类的 Save 方法保存文件

以下代码片段展示了使用 C++ 向 XPS 文档添加文本的完整功能。

 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Create new XPS Document
 3auto doc = System::MakeObject<XpsDocument>();
 4//Create a brush 
 5System::SharedPtr<XpsSolidColorBrush> textFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black());
 6//Add glyph to the document
 7System::SharedPtr<XpsGlyphs> glyphs = doc->AddGlyphs(u"Arial", 12.0f, System::Drawing::FontStyle::Regular, 300.f, 450.f, u"Hello World!");
 8glyphs->set_Fill(textFill);
 9// Save resultant XPS document
10doc->Save(outDir() + u"AddText_out.xps");

使用编码字符串添加文本

Aspose.Page for C++ 提供了 XpsGlyphs 类,您可以使用该类在 XPS 文档中使用编码字符串添加文本。 如果您需要将文本方向从从左到右更改为从右到左(例如希伯来语或阿拉伯语文本),请更改 BidiLevel 属性(默认值为“0”,即从左到右)

1glyphs->set_BidiLevel(1);

以下代码片段展示了使用编码字符串添加文本的完整功能

 1For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-C
 2// Create new XPS Document
 3auto doc = System::MakeObject<XpsDocument>();
 4// Add Text
 5System::SharedPtr<XpsSolidColorBrush> textFill = doc->CreateSolidColorBrush(System::Drawing::Color::get_Black());
 6System::SharedPtr<XpsGlyphs> glyphs = doc->AddGlyphs(u"Arial", 20.0f, System::Drawing::FontStyle::Regular, 400.f, 200.f, u"++C. rof SPX.esopsA");
 7glyphs->set_BidiLevel(1);
 8glyphs->set_Fill(textFill);
 9// Save resultant XPS document
10doc->Save(outDir() + u"AddText_out.xps");

Have any questions about Aspose.Page?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.