iTextSharp - C# - Make a font bold as well as underlined
Try the following:
Font header = new Font(Font.FontFamily.TIMES_ROMAN, 15f, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK);
As an alternative to using the Font
to underline text, you can also use the setUnderline()
method that is available for the Chunk
class. When you use the solution explained in the answer by Joachim Isaksson, you can choose the line width of the line, nor the distance from the baseline of the text. The setUnderline()
method gives you all that freedom.
Read my answer to the question How to strike through text using iText? for more info.
Take a look at these examples:
Chunk chunk1 = new Chunk("0123456789");
chunk1.SetUnderline(2, -3);
document.Add(new Phrase(chunk1));
Chunk chunk2 = new Chunk("0123456789");
chunk2.SetUnderline(2, 3);
document.Add(new Phrase(chunk2));
In both cases, the line that is drawn will be 2 user units thick instead of the default 1 user unit. In chunk1
the line will be drawn 3 user units under the text (this is underline functionality). In chunk2
, the line will be drawn above the baseline (this is strikethrough functionality).
I have used like this:
Dim font8Underline As Font = FontFactory.GetFont("ARIAL", 8, Font.BOLD)
font8Underline.SetStyle(Font.UNDERLINE)