如何使用 iText 将 FormField 添加到没有位置的部分?
How to add a FormField to section without a position using iText?
想要向新创建的多页 PDF 添加复选框等交互式表单域,在 iText 的 example 中,代码如下所示:
PdfContentByte canvas = writer.getDirectContent();
Rectangle rect = new Rectangle(180, 806 * 40, 200, 788 * 40);
RadioCheckField checkbox = new RadioCheckField(writer, rect, "box1", "Yes");
PdfFormField field = checkbox.getCheckField();
writer.addAnnotation(field);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("checkbox1", normal), 210, 790 * 40, 0);
但是这里使用的是绝对位置,我不知道位置,因为字段前面的内容有可选的图片和文本部分,我不知道他们占了多少行。
我也在使用章节,所以我想使用这样的东西:
Section section = chap.addSection(new Paragraph("sectionTitel",header2));
section.add(new Paragraph("line before field"));
//add FormField
section.add(field);
section.add(new Paragraph("line after field"));
你知道如何做这样的事情或者如何从之前的行中获取位置吗?
检查此示例以显示未指定位置的复选框或单选按钮。您需要使用 PdfPTable。 http://itextpdf.com/sandbox/acroforms/CreateRadioInTable . There is one issue for displaying radiobuttons on multiple pages which I have posted here Issue with iText RadioCheckField when displayed on multiple pages 仍在等待答案
想要向新创建的多页 PDF 添加复选框等交互式表单域,在 iText 的 example 中,代码如下所示:
PdfContentByte canvas = writer.getDirectContent();
Rectangle rect = new Rectangle(180, 806 * 40, 200, 788 * 40);
RadioCheckField checkbox = new RadioCheckField(writer, rect, "box1", "Yes");
PdfFormField field = checkbox.getCheckField();
writer.addAnnotation(field);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("checkbox1", normal), 210, 790 * 40, 0);
但是这里使用的是绝对位置,我不知道位置,因为字段前面的内容有可选的图片和文本部分,我不知道他们占了多少行。 我也在使用章节,所以我想使用这样的东西:
Section section = chap.addSection(new Paragraph("sectionTitel",header2));
section.add(new Paragraph("line before field"));
//add FormField
section.add(field);
section.add(new Paragraph("line after field"));
你知道如何做这样的事情或者如何从之前的行中获取位置吗?
检查此示例以显示未指定位置的复选框或单选按钮。您需要使用 PdfPTable。 http://itextpdf.com/sandbox/acroforms/CreateRadioInTable . There is one issue for displaying radiobuttons on multiple pages which I have posted here Issue with iText RadioCheckField when displayed on multiple pages 仍在等待答案