Add Fonts in PDF using iText

Using the iText framework we have seen how to add text/paragraphs to PDF files. Now we will see how we can add various fonts and colors to the text that is added. Lets see an example on how to Add Fonts in PDF using iText.

Important class – com.itextpdf.text.Font

For setting font color use either
a) setColor(BaseColor color)
b) setColor(int red, int green, int blue)

For setting size of the font use
a) setSize(float size)

For setting font style i.e (normal, bold, italic, oblique, underline, line-through) use
a) setStyle(String style)

Example

In this example we take two paragraphs and add various fonts, colors and styles to them.

Output
Add Fonts in PDF using iText

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn