iText is a free and open source library for creating and manipulating
PDF documents in Java. The following example shows adding a Chunk with underline to PDF document.
Document document = new Document(PageSize.A4);
PdfWriter.getInstance(document, new FileOutputStream("test24.pdf"));
//Open the document before adding any content
document.open();
Paragraph paragraph = new Paragraph("BE THE CODER");
paragraph.add("\n"); //new line
//the smallest significant part of text that can be added to a document
Chunk chunk = new Chunk("be the coder");
chunk.setBackground(BaseColor.YELLOW);
chunk.setUnderline(1, -2); //(thickness, y-position)