Hello,
I wrote a while back asking some questions about adding various fields
to an existing PDF. Since then, I've mostly solved the issue by:
1. Reading the existing PDF doc with PDFBox and detecting where I want
to insert the various text and checkbox fields; then
2. Use iText to actually insert the fields.
Everything works perfectly for inserting text fields. However,
RadioCheckBoxes are not being inserted. Once I calculate the
location for a
text field I use the following to insert it:
private void addTextField( PdfStamper stamper, Rectangle rect,
String name, int pagenumber ) throws DocumentException, IOException
{
log.debug("Creating Text Field at X = " + rect.getLeft() + " Y
= " + rect.getRight() + " Width = " + rect.getWidth() + " Height = " +
rect.getHeight());
TextField field = new TextField(stamper.getWriter(), rect, name);
field.setAlignment(Element.ALIGN_CENTER);
field.setOptions(TextField.MULTILINE);
field.setText("Field Page " + pagenumber);
stamper.addAnnotation(field.getTextField(), pagenumber);
}
I couldn't find an example for setting a RadioCheckBox, so I'm using:
private void addCheckboxField( PdfStamper stamper, Rectangle rect,
String name, int pagenumber ) throws DocumentException, IOException
{
log.debug("Creating Checkbox Field at X = " + rect.getLeft() +
" Y = " + rect.getRight() + " Width = " + rect.getWidth() + " Height =
" + rect.getHeight() + " Page = " + pagenumber);
RadioCheckField field = new
RadioCheckField(stamper.getWriter(), rect, name, "On");
field.setCheckType(RadioCheckField.TYPE_CROSS);
field.setChecked(false);
field.setBorderWidth(BaseField.BORDER_WIDTH_THIN);
field.setBorderColor(Color.black);
field.setBackgroundColor(Color.white);
stamper.addAnnotation(field.getRadioField(), pagenumber);
}
Basically identical to the addTextField method. Just to verify I have
the right coordinates for the rectangle, I have called the
addTextField with the
desired checkbox values, and it properly inserts a text field. I'm
guessing I'm missing something in the addCheckboxField method. Some
of the method calls are
likely extraneous because I've been trying just about everything to
make it work. Any suggestions?
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php