admin管理员组文章数量:1649163
I am using Itext to create a pdf and I cannot get the checkbox to uncheck. Here is my code:
RadioCheckField bt = new RadioCheckField(writer, new Rectangle(300, 300, 400, 400),
"check1", "Yes");
bt.setCheckType(RadioCheckField.TYPE_CHECK);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
bt.setBorderColor(BaseColor.BLACK);
bt.setBackgroundColor(BaseColor.WHITE);
bt.setChecked(false);
PdfFormField ck = bt.getCheckField();
writer.addAnnotation(ck);
You can see that the bt.setChecked(false) is in the code, but the checkbox is still checked. I looked at the docs and it seems to me that it is supposed to work this way. What do I not understand?
解决方案
Try the following way, for me it is working:
public void addRadioGroup() throws Exception{
if(!this.doc.isOpen()){
this.doc.open();
}
PdfFormField radioGroup = PdfFormField.createRadioButton(this.writer, false);
radioGroup.setFieldName("numbers");
for(int i=0;i<3;i++){
Rectangle rect = new Rectangle(130+(40*i), 430, 160+(40*i), 455);
this.addRadioButtonKid(radioGroup, rect,String.valueOf(i));
}
this.writer.addAnnotation(radioGroup);
}
private void addRadioButtonKid(PdfFormField radio, Rectangle rect, String onValue) throws Exception{
RadioCheckField bt = new RadioCheckField(this.writer, rect, null, onValue);
bt.setBorderWidth(BaseField.BORDER_WIDTH_THICK);
bt.setBorderColor(Color.BLACK);
bt.setBackgroundColor(Color.WHITE);
bt.setCheckType(RadioCheckField.TYPE_CROSS);
bt.setChecked(false);
PdfFormField ck = bt.getCheckField();
ck.setPlaceInPage(1);
radio.addKid(ck);
}
The only problem I had was that the default "check style" wasn't changed. A user reported this problem back in 2011 on the mailinglist in 2011. If you need another style patch iText for yourself or use the workaround described by Mark.
Update: After 2 years they seem to have fixed the problem in the latest iText version 5.4.3 (cp. the change of Michaël Demey)
版权声明:本文标题:itextpdf将带复选框的html,始终选中Itext复选框 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729505427a1203570.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论