Underline selected text in paragraph

I am using the following code to add text as a paragraph:



mainBody = New Text(sec1, " 1. TREATMENT PLANNING AND SUPPORT - Described representative treatment planning")

sec1.Paragraphs.Add(mainBody)



I would like to underline just TREATMENT PLANNING AND SUPPORT



How can I change formatting within a paragraph?

Hello Mark,

Thanks for considering Aspose.

Please use text segments while adding the text object to Pdf section. You can specify explicit text formatting for the particular segment. Try using the following code snippet to accomplish you requirement.

[C#]

//Instantiate Pdf object by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a section in the Pdf object
Aspose.Pdf.Section sec1 = pdf1.Sections.Add();

//Create a new text paragraph with an initial text segment "Aspose"
Text text1 = new Text(sec1, "1.");

//Add the text paragraph to the section
sec1.Paragraphs.Add(text1);
//Create a new text segment into the text paragraph
Segment seg1 = text1.Segments.Add("TREATMENT PLANNING AND SUPPORT ");
//Set the Underline property of seg1.TextInfo to true
seg1.TextInfo.IsUnderline= true;
Segment seg2 = text1.Segments.Add("- Described representative treatment planning");

//Save the Pdf
pdf1.Save(@"d:\pdftest\TextSegment.pdf");

The resultant PDF that I've generated is also in attachment, please take a look. In case of any further query, feel free to contact.