Aspose.Pdf also provides basic text formatting effects like underline, overline and strike out. We know that we apply text formatting effects using Text.TextInfo property. TextInfo class has a few boolean properties to apply such effects on the text as follows:
We can set the IsUnderline IsOverline and IsStrikeOut properties of TextInfo to true to make the text underline, overline and strike out.
Code Snippet
[C#]
//Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf()
//Create a section in the Pdf object
Section sec1 = pdf1.Sections.Add();
//Create 1st text paragraph
Text text1 = new Text(sec1,"Text underline");
//Set IsUnderline property of Text.TextInfo to true
text1.TextInfo.IsUnderline=true;
//Create 2nd text paragraph
Text text2 = new Text(sec1,"Text overline");
//Set IsOverline property of Text.TextInfo to true
text2.TextInfo.IsOverline=true;
//Create 3rd text paragraph
Text text3 = new Text(sec1,"Text strike out");
//Set IsStrikeOut property of Text.TextInfo to true
text3.TextInfo.IsStrikeOut=true;
//Add 1st, 2nd and 3rd text paragraphs to the section
sec1.Paragraphs.Add(text1);
sec1.Paragraphs.Add(text2);
sec1.Paragraphs.Add(text3);
//Save the Pdf
pdf1.Save(...);
[VB.NET]
'Instantiate Pdf instance by calling its empty constructor
Dim pdf1 As Pdf = New Pdf()
'Create a section in the Pdf object
Dim sec1 As Section = pdf1.Sections.Add()
'Create 1st text paragraph
Dim text1 As Text = New Text(sec1,"Text underline")
'Set IsUnderline property of Text.TextInfo to true
text1.TextInfo.IsUnderline=true
'Create 2nd text paragraph
Dim text2 As Text = New Text(sec1,"Text overline")
'Set IsOverline property of Text.TextInfo to true
text2.TextInfo.IsOverline=true
'Create 3rd text paragraph
Dim text3 As Text = New Text(sec1,"Text strike out")
'Set IsStrikeOut property of Text.TextInfo to true
text3.TextInfo.IsStrikeOut=true
'Add 1st, 2nd and 3rd text paragraphs to the section
sec1.Paragraphs.Add(text1)
sec1.Paragraphs.Add(text2)
sec1.Paragraphs.Add(text3)
'Save the Pdf
pdf1.Save(...)
[JAVA]
//Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
//Create 1st text paragraph
Text text1 = new Text(sec1,"Text underline");
//Set IsUnderline property of Text.TextInfo to true
text1.getTextInfo().setUnderLine(true);
//Create 2nd text paragraph
Text text2 = new Text(sec1,"Text overline");
//OverLine is not supported at present
//text2.getTextInfo().setOverLine(true);
//Create 3rd text paragraph
Text text3 = new Text(sec1,"Text strike out");
//Set IsStrikeOut property of Text.TextInfo to true
text3.getTextInfo().setStrikeOut(true);
//Add 1st, 2nd and 3rd text paragraphs to the section
sec1.getParagraphs().add(text1);
sec1.getParagraphs().add(text2);
sec1.getParagraphs().add(text3);
//Save the Pdf
FileOutputStream out = new FileOutputStream(new File("..."));
pdf1.save(out);
Using the above code, will produce the output as follows:
|