java itext pdf 怎样将复选框打上对号
2017-04-04 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
要将页面报表导出到pdf中,但是报表中有checkbox复选框,需要要后台利用itext生成,生成复选框的方法如下:
PdfContentByte cb = writer.getDirectContent();
cb.moveTo(0, 0);
PdfFormField field = PdfFormField.createCheckBox(writer);
PdfAppearance tpOff = cb.createAppearance(20, 20);
PdfAppearance tpOn = cb.createAppearance(20, 20);
tpOff.rectangle(1, 1, 18, 18);
tpOff.stroke();
//
tpOn.setRGBColorFill(255, 128, 128);
tpOn.rectangle(1, 1, 18, 18);
tpOn.fillStroke();
tpOn.moveTo(1, 1);
tpOn.lineTo(19, 19);
tpOn.moveTo(1, 19);
tpOn.lineTo(19, 1);
tpOn.stroke();
field.setWidget(new Rectangle(100, 700, 120, 720), PdfAnnotation.HIGHLIGHT_INVERT);
field.setFieldName("Urgent");
field.setValueAsName("On");
field.setAppearanceState("Off");
// field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
// field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn);
writer.addAnnotation(field);
PdfContentByte cb = writer.getDirectContent();
cb.moveTo(0, 0);
PdfFormField field = PdfFormField.createCheckBox(writer);
PdfAppearance tpOff = cb.createAppearance(20, 20);
PdfAppearance tpOn = cb.createAppearance(20, 20);
tpOff.rectangle(1, 1, 18, 18);
tpOff.stroke();
//
tpOn.setRGBColorFill(255, 128, 128);
tpOn.rectangle(1, 1, 18, 18);
tpOn.fillStroke();
tpOn.moveTo(1, 1);
tpOn.lineTo(19, 19);
tpOn.moveTo(1, 19);
tpOn.lineTo(19, 1);
tpOn.stroke();
field.setWidget(new Rectangle(100, 700, 120, 720), PdfAnnotation.HIGHLIGHT_INVERT);
field.setFieldName("Urgent");
field.setValueAsName("On");
field.setAppearanceState("Off");
// field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
// field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "On", tpOn);
writer.addAnnotation(field);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询