|
From: Bruno Lowagie <bruno <at> lowagie.com>
Subject: Re: Extracting form field meta data Newsgroups: gmane.comp.java.lib.itext.general Date: 2006-02-10 12:13:07 GMT (3 years, 20 weeks, 4 days, 6 hours and 51 minutes ago)
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
|
|
|