請看看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