browser icon
You are using an insecure version of your web browser. Please update your browser!
Using an outdated browser makes your computer unsafe. For a safer, faster, more enjoyable user experience, please update your browser today or try a newer browser.

gettinig PDF form field names

Posted by on October 21, 2009

If you have a PDF and want to fill the pdf programmatic-ally, You can but you need those pdf’s form fields.

Here’s a simple Java Class which can help you. I am using iText as my PDF library.

import java.util.HashMap;
import java.util.Iterator;
import com.lowagie.text.pdf.*;

public class iTextSample {
public static void main(String[] args) throws Exception{
PdfReader reader = new PdfReader(“/Users/Admin/Public/jars/a.pdf”);
boolean test = reader.isEncrypted();

System.out.println(test);

AcroFields form = reader.getAcroFields();
HashMap fields = form.getFields();
System.out.println(“Total Fields: ” + fields.size());
String key;
for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {
key = (String) i.next();
switch(form.getFieldType(key)) {

case AcroFields.FIELD_TYPE_TEXT:
{
System.out.print(key + “: “);
System.out.print(“Text”);
System.out.print(“, At Page:” + form.getFieldItem(key).getPage(0));
System.out.println(“, at tab:” + form.getFieldItem(key).getTabOrder(0));
}
break;

}
}
}
}

People who read this article also read these...

    3 Responses to gettinig PDF form field names

    1. Pdf To Word Converters

      hello there, i just discovered your blog via yahoo, and i must tell that you compose exceptionally good via your blog. i am actually taken by the mode that you compose, and the content is excellent. anyway, i would also love to know whether you would love to exchange links with my web portal? i will be to the great extent than willing to reciprocate and insert your link off in the link section. looking for your reply, i give my sincere thanks and gooday!

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Get Adobe Flash playerPlugin by wpburn.com wordpress themes