{throw new RuntimeException(filePath + " file access error.",e);}
Document document = file.getDocument();
// 2. Get the acroform!
Form form = document.getForm();
if(form == null)
{System.out.println("\nNo acroform available (AcroForm dictionary not found).");}
else
{
System.out.println("\nIterating through the fields collection...\n");
// 3. Showing the acroform fields...
HashMap<String,Integer> objCounters = new HashMap<String,Integer>();
for(Field field : form.getFields().values())
{
System.out.println("* Field '" + field.getFullName() + "' (" + field.getBaseObject() + ")");
String typeName = field.getClass().getSimpleName();
System.out.println(" Type: " + typeName);
System.out.println(" Value: " + field.getValue());
System.out.println(" Data: " + field.getBaseDataObject().toString());
int widgetIndex = 0;
for(Widget widget : field.getWidgets())
{
System.out.println(" Widget " + (++widgetIndex) + ":");
Page widgetPage = widget.getPage();
System.out.println(" Page: " + (widgetPage == null ? "undefined" : (widgetPage.getIndex() + 1) + " (" + widgetPage.getBaseObject() + ")"));
Rectangle2D widgetBox = widget.getBox();
System.out.println(" Coordinates: {x:" + Math.round(widgetBox.getX()) + "; y:" + Math.round(widgetBox.getY()) + "; width:" + Math.round(widgetBox.getWidth()) + "; height:" + Math.round(widgetBox.getHeight()) + "}");
}
objCounters.put(typeName, (objCounters.containsKey(typeName) ? objCounters.get(typeName) : 0) + 1);
}
int fieldCount = form.getFields().size();
if(fieldCount == 0)
{System.out.println("No field available.");}
else
{
System.out.println("\nFields partial counts (grouped by type):");