请看看CreateRadioInTable的例子。
在这个例子中,我们创建用于所述无线电基的PdfFormField
,我们构建并添加表后添加:
PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
radiogroup.setFieldName("Language");
PdfPTable table = new PdfPTable(2);
// add cells
document.add(table);
writer.addAnnotation(radiogroup);
当我们创建细胞单选按钮,我们添加一个事件,例如:
cell.setCellEvent(new MyCellField(radiogroup, "english"));
事件看起来是这样的:
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);
}
}
}
梦幻般的答案!非常感谢! – corestruct00 2015-04-01 17:31:51