To add styles to characters or paragraphs in an IText object, create the appropriate styles with the correct values and apply them to a specific character range:
IText styledString("Hello World!");
// Create a style set
ITextStyleSet stylesToAdd;
// Add styles to the style set
stylesToAdd.add(ITextPointSizeStyle(12));
stylesToAdd.add(ITextTypefaceStyle("Courier");
stylesToAdd.add(ITextUnderlineStyle(true));
// Apply styles to the entire string
styledString.addStyles(stylesToAdd, 0, IText::npos);
// Apply another style only to the first word
styledString.addStyles(ITextUnderlineStyle(true), 0, 5);
IParagraphJustificationStyle pstyle(IParagraphJustificationStyle::kCenter); styledString.addStyles(pstyles, 0, 1);