Working with Text | C++ API Solution
Add Text
Add Text to XPS Document
Aspose.Page for C++ lets you add text to an XPS document in your C++ applications. The XpsGlyphs class lets you add text to an XPS document by specifying the brush of your choice. Text can be added to an XPS document using the following steps:
- Create a new instance of XPSDocument class
- Create a brush using the XpsSolidColorBrush class
- Add glyphs to the document object with required font information
- Save the file using the Save method of XPSDocument class
The following code snippet shows complete functionality for adding text to an XPS document using C++.
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");
Add Text Using Encoding String
Aspose.Page for C++ offers� XpsGlyphs�Class, with which you can add text using Encoding String on an XPS document. If you need change direction form left-to-right to right-to-left, as in Hebrew or Arabic texts, change BidiLevel property, which default value is “0”, that is left-to-right.
1glyphs->set_BidiLevel(1);
Following code snippet shows complete functionality to add text using encoding string:
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");