java - iText RadioGroup/RadioButtons across multiple PdfPCells -
i'd make pdfptable multiple rows in it. in each row i'd have radio button in first cell , descriptive text in second cell. i'd radio buttons part of same radio group.
i've used pdfpcell.setcellevent , own custom cellevents in past render textfields , checkboxes in pdfptables. however, can't seem figure out how radio buttons/radio groups.
is possible itext? have example?
please take @ createradiointable example.
in example, create pdfformfield
radio group , add after constructing and adding table:
pdfformfield radiogroup = pdfformfield.createradiobutton(writer, true); radiogroup.setfieldname("language"); pdfptable table = new pdfptable(2); // add cells document.add(table); writer.addannotation(radiogroup);
when create cells radio buttons, add event, instance:
cell.setcellevent(new mycellfield(radiogroup, "english"));
the event looks this:
class mycellfield implements pdfpcellevent { protected pdfformfield radiogroup; protected string value; public mycellfield(pdfformfield radiogroup, string value) { this.radiogroup = radiogroup; this.value = value; } public void celllayout(pdfpcell cell, rectangle rectangle, pdfcontentbyte[] canvases) { final pdfwriter writer = canvases[0].getpdfwriter(); radiocheckfield radio = new radiocheckfield(writer, rectangle, null, value); try { radiogroup.addkid(radio.getradiofield()); } catch (final ioexception ioe) { throw new exceptionconverter(ioe); } catch (final documentexception de) { throw new exceptionconverter(de); } } }
Comments
Post a Comment