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:

  1. Create a new instance of XPSDocument class
  2. Create a brush using the XpsSolidColorBrush class
  3. Add glyph to the document object with required font information
  4. 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. You need to specify a brush using BidiLevel property of XpsGlyphs class. 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");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.