iText pdf library
Website search

How to create radio buttons inside a table?

How do I use iText 7 to create a table with a radio button inside?

I know how to create a table and I know how to add a radio field using Rectangle objects that define the position of the radio buttons on the page. What I don't know, is how to make sure that these radio buttons appear inside my table.

Posted on StackOverflow on Oct 30, 2015 by Vikash

Please take a look at the CreateRadioInTable example.

In this example, we create a PdfButtonFormField for the radio group and we add it after constructing and adding the table:

PdfButtonFormField group = PdfFormField.createRadioGroup(pdfDoc, "Language", "English");
Table table = new Table(2);
// add cells
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);

When we create the cells for the radio buttons, we set a renderer, for instance:

cell.setNextRenderer(new MyCellRenderer(cell, group, "english"));

The renderer looks like this:

private class MyCellRenderer extends CellRenderer {
    protected String value;
    protected PdfButtonFormField radioGroup;
    public MyCellRenderer(Cell modelElement, PdfButtonFormField radioGroup, String fieldName) {
        this.radioGroup = radioGroup;
        this.value = fieldName;
    public void draw(DrawContext drawContext) {
        PdfFormField.createRadioButton(drawContext.getDocument(), getOccupiedAreaBBox(), radioGroup, value);

Click this link if you want to see how to answer this question in iText 5.


Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now