Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Monday, August 4, 2008

PDF Forms by using iText

Hi All,

We have one situation. we want to read pdf forms. I am posting how we can read and manipulate pdf form with iText, an open source library.

I am sure it will help you all to avoid using commercial products like JPadel etc.

Find the example as follows and enjoy the usage of iText


PdfReader reader = new PdfReader("C:/MyForm.pdf");

AcroFields form = reader.getAcroFields();

HashMap fields = form.getFields();

String key;

for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {

key = (String) i.next();

System.out.print(key + ": ");

switch(form.getFieldType(key)) {


case AcroFields.FIELD_TYPE_CHECKBOX:
System.out.println("Checkbox");
break;
case AcroFields.FIELD_TYPE_COMBO:
System.out.println("Combobox");
break;
case AcroFields.FIELD_TYPE_LIST:
System.out.println("List");
break;
case AcroFields.FIELD_TYPE_NONE:

System.out.println("None");
break;

case AcroFields.FIELD_TYPE_PUSHBUTTON:
System.out.println("Pushbutton");
break;

case AcroFields.FIELD_TYPE_RADIOBUTTON:
System.out.println("Radiobutton");
break;

case AcroFields.FIELD_TYPE_SIGNATURE:
System.out.println("Signature");
break;

case AcroFields.FIELD_TYPE_TEXT:
System.out.println("Text");
System.out.println(" Value : "+form.getField(key));
break;

default:
System.out.println("?");
}

}

cheers and enjoy iText