0

In want to add interactive formfields like checkboxes to a newly created multiple page PDF, in the example from iText the code looks like this:

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);

But this uses absolute positions and I don't know the position because the content before the field has optional images and text parts, where I don't know how many lines they take. I am also using Chapters and Sections, so I would like to use something like this:

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"));

Have you an idea how to do something like this or how to get the position from the line before ?

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
stm
  • 174
  • 1
  • 2
  • 11

1 Answers1

0

Check this example for displaying checkboxes or radiobuttons without specifying positions. You need to use 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 and still waiting for answers

Community
  • 1
  • 1
  • For checkboxes the cellLayout method hast to look like in this example The problem with multiple pages doesn't occur with the checkboxes, however the reason for this probably is that they have no radiogroup. – stm Jun 18 '15 at 02:14