Hello, I managed adding textfield to cell, but the text is odd and is stretching inside of it. Also, the textbox is always fitting to the cell. Heres a pic of how it is:
[image: Imagem inline 1]
The 1st "Some text" is when there is text inside of a editable textfield,
after I change it, it stays centered perfectly with no problems. If i
create a textfield not editable, the text goes that way, even after setting
the size. And the border of ir, i`m not managing to let it thin, when I set
to thin, the border is dotted.
heres my method:
public void addTextField(PdfPTable table, PdfWriter pw, String fieldId,
String fieldText, boolean editable) throws IOException, DocumentException {
Rectangle rectangle = new Rectangle(0,0,100,10);
rectangle.setBorder(0);
TextField textField = new TextField(pw, rectangle, fieldId);
textField.setBackgroundColor(Color.WHITE);
textField.setBorderColor(Color.BLACK);
textField.setBorderWidth(0.2f);
textField.setText(fieldText);
textField.setFontSize(8);
textField.setAlignment(Element.ALIGN_BOTTOM);
textField.setBorderStyle((int)TextField.BORDER_WIDTH_MEDIUM);
PdfFormField pff = textField.getTextField();
if (editable){
pff.setFieldFlags(PdfFormField.FF_READ_ONLY);
}
PdfPCell cell = new PdfPCell();
cell.setCellEvent(new FieldPositioningEvents(writer, pff));
table.addCell(cell);
}
Thanks :D
2013/7/4 André Fróes <[email protected]>
> Hello everyone! I`m trying to do a method here in my application to create
> Radio, checkbox or textfield inside a cell, but i`m not managing to do it.
> I managed doing it with a select, but when I try any of those, it doesn`t
> work at all.
>
> Here`s my workaround:
>
> Working select method:
>
> public void createSelectBox(Rectangle rectangle, PdfContentByte[] canvas,
> String[] options, String[] exportOptions, boolean readOnly)
> throws IOException, DocumentException {
> PdfWriter pw = canvas[0].getPdfWriter();
> TextField tf = new TextField(pw, rectangle,
> String.format("option_%s", type));
> tf.setChoices(options);
> tf.setChoiceExports(exportOptions);
> tf.setChoiceSelection(4);
> PdfFormField field2 = tf.getComboField();
> if (readOnly) {
> field2.setFieldFlags(PdfFormField.FF_READ_ONLY);
> }
> pw.addAnnotation(field2);
> }
>
> it is invoked from a switch:
>
> @Override
> public void cellLayout(PdfPCell cell, Rectangle rectangle,
> PdfContentByte[] canvas) {
> try {
> switch (type) {
> case FIELD_TYPE_CHECKBOX:
> createCheckBoxField(rectangle);
> break;
> case FIELD_TYPE_RADIO:
> createField(rectangle, canvas, checked, fieldName,
> type, readOnly);
> break;
> case FIELD_TYPE_SELECT:
> createSelectBox(rectangle, canvas, options,
> exportOptions, readOnly);
> break;
> }
> } catch (IOException | DocumentException ex) {
> throw new ExceptionConverter(ex);
> }
> }
>
> works just fine. But when I try to do anything like with redio or check,
> no success at all:
>
> this is the checkbox atempt:
>
> public void createCheckBoxField(Rectangle rect) throws IOException,
> DocumentException {
> RadioCheckField rf = new RadioCheckField(writer, new
> Rectangle(rect.getLeft(4), rect.getBottom(4),
> rect.getRight(4), rect.getTop(4)), fieldName, "");
> rf.setChecked(checked);
> rf.setBorderColor(GrayColor.GRAYBLACK);
> rf.setBackgroundColor(GrayColor.GRAYWHITE);
> rf.setCheckType(RadioCheckField.TYPE_CHECK);
> formField.addKid(rf.getCheckField());
> }
>
> I`m searching all over the internet but not having much of success rate :D
> Thanks for the help
>
>
>
<<textfield.png>>
------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
