org.pdfbox.pdmodel.interactive.form
Class PDAcroForm

java.lang.Object
  extended byorg.pdfbox.pdmodel.interactive.form.PDAcroForm

public class PDAcroForm
extends Object

This class represents the acroform of a PDF document.

Version:
$Revision: 1.8 $
Author:
Ben Litchfield (ben@csh.rit.edu)

Constructor Summary
PDAcroForm(PDDocument doc)
          Constructor.
PDAcroForm(PDDocument doc, COSDictionary form)
          Constructor.
 
Method Summary
 FDFDocument exportFDF()
          This will export all FDF form data.
 PDResources getDefaultResources()
          This will get the default resources for the acro form.
 COSDictionary getDictionary()
          This will get the dictionary that this form wraps.
 PDDocument getDocument()
          This will get the document associated with this form.
 PDField getField(String name)
          This will get a field by name, possibly using the cache if setCache is true.
 List getFields()
          This will return all of the fields in the document.
 void importFDF(FDFDocument fdf)
          This method will import an entire FDF document into the PDF document that this acroform is part of.
 boolean isCachingFields()
          This will tell if this acro form is caching the fields.
 void setCacheFields(boolean cache)
          This will tell this form to cache the fields into a Map structure for fast access via the getField method.
 void setDefaultResources(PDResources dr)
          This will set the default resources for the acroform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDAcroForm

public PDAcroForm(PDDocument doc)
Constructor.

Parameters:
doc - The document that this form is part of.

PDAcroForm

public PDAcroForm(PDDocument doc,
                  COSDictionary form)
Constructor.

Parameters:
doc - The document that this form is part of.
form - The existing acroForm.
Method Detail

getDocument

public PDDocument getDocument()
This will get the document associated with this form.

Returns:
The PDF document.

getDictionary

public COSDictionary getDictionary()
This will get the dictionary that this form wraps.

Returns:
The dictionary for this form.

importFDF

public void importFDF(FDFDocument fdf)
               throws IOException
This method will import an entire FDF document into the PDF document that this acroform is part of.

Parameters:
fdf - The FDF document to import.
Throws:
IOException - If there is an error doing the import.

exportFDF

public FDFDocument exportFDF()
                      throws IOException
This will export all FDF form data.

Returns:
An FDF document used to export the document.
Throws:
IOException - If there is an error when exporting the document.

getFields

public List getFields()
               throws IOException
This will return all of the fields in the document. The type will be a org.pdfbox.pdmodel.field.PDField.

Returns:
A list of all the fields.
Throws:
IOException - If there is an error while getting the list of fields.

setCacheFields

public void setCacheFields(boolean cache)
                    throws IOException
This will tell this form to cache the fields into a Map structure for fast access via the getField method. The default is false. You would want this to be false if you were changing the COSDictionary behind the scenes, otherwise setting this to true is acceptable.

Parameters:
cache - A boolean telling if we should cache the fields.
Throws:
IOException - If there is an error while caching the fields.

isCachingFields

public boolean isCachingFields()
This will tell if this acro form is caching the fields.

Returns:
true if the fields are being cached.

getField

public PDField getField(String name)
                 throws IOException
This will get a field by name, possibly using the cache if setCache is true.

Parameters:
name - The name of the field to get.
Returns:
The field with that name of null if one was not found.
Throws:
IOException - If there is an error getting the field type.

getDefaultResources

public PDResources getDefaultResources()
This will get the default resources for the acro form.

Returns:
The default resources.

setDefaultResources

public void setDefaultResources(PDResources dr)
This will set the default resources for the acroform.

Parameters:
dr - The new default resources.