By Date: <-- -->
By Thread: <-- -->

Extracting form field meta data



Leonard Rosenthol wrote:

At 10:02 PM 2/9/2006, Richard Braman wrote:

I am trying to extract form field meta data out of a PDF form that uses FDF.
I want the data about the fields on the form including:


name of field
type of field (textbox, checkbox, etc)
location of field (rectangle)
font size used for text

I need this on a page by page basis, in other words I to iterate through each pages in a document and etxract this meta data page by page.


There are samples of doing this in the iText distribution.

Unfortunately the ListFields example uses some legacy methods. For the book 'iText in Action' (I only have one more chapter to write!), I have made a new example. I'm just copying and pasting from the (not yet published) book:

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... (other types)
 }
}
float[] positions = form.getFieldPositions(key);
for (int i = 0; i < positions.length; ) {
 System.out.print("Page: " + positions[i++]);
 System.out.print(" [ " + positions[i++]);
 System.out.print(", " + positions[i++]);
 System.out.print(", " + positions[i++]);
 System.out.print(", " + positions[i++]);
 System.out.println(" ]");
}
AcroFields.Item item = form.getFieldItem(key);
PdfDictionary dict;
PdfName name;
System.out.println("pages: " + item.page);
for (Iterator i = item.merged.iterator(); i.hasNext(); ) {
 dict = (PdfDictionary)i.next();
 for (Iterator it = dict.getKeys().iterator(); it.hasNext(); ) {
   name = (PdfName)it.next();
   System.out.println(name.toString() + ": " + dict.get(name));
 }
 System.out.println("------------------------------------");
}

I don't think my publisher would appreciate it if I posted
a complete explanation of these code snippets, so you'll
have to find out yourself what is returned by every method.
You can do this using the PDF Reference. Otherwise you'll
have to wait for the book ;-)
br,
Bruno



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions