Search code examples
javaitext7

How to add a check box in a PDF file using iText 7?


How can I add a checkobox into a Pdf file like it is done in this question, but using iText 7?

I want the result to look like this:

expected result


Solution

  • Adapting Bruno's answer to iText 7:

    Paragraph p = new Paragraph("This is a tick box character: ");
    PdfFont zapfdingbats = PdfFontFactory.createFont(FontConstants.ZAPFDINGBATS);
    Text chunk = new Text("4").setFont(zapfdingbats).setFontSize(14);
    p.add(chunk);
    document.add(p);