com.lowagie.text.pdf
Class AcroFields

java.lang.Object
  extended bycom.lowagie.text.pdf.AcroFields

public class AcroFields
extends Object

Query and change fields in existing documents either by method calls or by FDF merging.

Author:
Paulo Soares (psoares@consiste.pt)

Nested Class Summary
static class AcroFields.Item
          The field representations for retrieval and modification.
 
Field Summary
(package private)  HashMap fields
           
private  boolean generateAppearances
          Holds value of property generateAppearances.
(package private)  PdfReader reader
           
private  int topFirst
           
(package private)  PdfWriter writer
           
 
Constructor Summary
(package private) AcroFields(PdfReader reader, PdfWriter writer)
           
 
Method Summary
(package private)  void fill()
           
(package private)  PdfAppearance getAppearance(PdfDictionary merged, String text)
           
 String[] getAppearanceStates(String fieldName)
          Gets the list of appearance names.
 String getField(String name)
          Gets the field value.
 AcroFields.Item getFieldItem(String name)
          Gets the field structure.
 float[] getFieldPositions(String name)
          Gets the field box positions in the document.
 HashMap getFields()
          Gets all the fields.
(package private)  Color getMKColor(PdfArray ar)
           
 boolean isGenerateAppearances()
          Gets the property generateAppearances.
(package private)  boolean isInAP(PdfDictionary dic, PdfName check)
           
 boolean removeField(String name)
          Removes a field from the document.
 boolean removeField(String name, int page)
          Removes a field from the document.
 boolean removeFieldsFromPage(int page)
          Removes all the fields from page.
private  int removeRefFromArray(PdfArray array, PdfObject refo)
           
 boolean renameField(String oldName, String newName)
          Renames a field.
 boolean setField(String name, String value)
          Sets the field value.
 boolean setField(String name, String value, String display)
          Sets the field value and the display string.
 void setFields(FdfReader fdf)
          Sets the fields by FDF merging.
 void setGenerateAppearances(boolean generateAppearances)
          Sets the option to generate appearances.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reader

PdfReader reader

writer

PdfWriter writer

fields

HashMap fields

topFirst

private int topFirst

generateAppearances

private boolean generateAppearances
Holds value of property generateAppearances.

Constructor Detail

AcroFields

AcroFields(PdfReader reader,
           PdfWriter writer)
Method Detail

fill

void fill()

getAppearanceStates

public String[] getAppearanceStates(String fieldName)
Gets the list of appearance names. Use it to get the names allowed with radio and checkbox fields. The name 'Off' may also be valid even if not returned in the list.

Parameters:
fieldName - the fully qualified field name
Returns:
the list of names or null if the field does not exist

renameField

public boolean renameField(String oldName,
                           String newName)
Renames a field. Only the last part of the name can be renamed. For example, if the original field is "ab.cd.ef" only the "ef" part can be renamed.

Parameters:
oldName - the old field name
newName - the new field name
Returns:
true if the renaming was successful, false otherwise

getAppearance

PdfAppearance getAppearance(PdfDictionary merged,
                            String text)
                      throws IOException,
                             DocumentException
Throws:
IOException
DocumentException

getMKColor

Color getMKColor(PdfArray ar)

getField

public String getField(String name)
Gets the field value.

Parameters:
name - the fully qualified field name
Returns:
the field value

setFields

public void setFields(FdfReader fdf)
               throws IOException,
                      DocumentException
Sets the fields by FDF merging.

Parameters:
fdf - the FDF form
Throws:
IOException - on error
DocumentException - on error

setField

public boolean setField(String name,
                        String value)
                 throws IOException,
                        DocumentException
Sets the field value.

Parameters:
name - the fully qualified field name
value - the field value
Returns:
true if the field was found and changed, false otherwise
Throws:
IOException - on error
DocumentException - on error

setField

public boolean setField(String name,
                        String value,
                        String display)
                 throws IOException,
                        DocumentException
Sets the field value and the display string. The display string is used to build the appearance in the cases where the value is modified by Acrobat with JavaScript and the algorithm is known.

Parameters:
name - the fully qualified field name
value - the field value
display - the string that is used for the appearance
Returns:
true if the field was found and changed, false otherwise
Throws:
IOException - on error
DocumentException - on error

isInAP

boolean isInAP(PdfDictionary dic,
               PdfName check)

getFields

public HashMap getFields()
Gets all the fields. The fields are keyed by the fully qualified field name and the value is an instance of AcroFields.Item.

Returns:
all the fields

getFieldItem

public AcroFields.Item getFieldItem(String name)
Gets the field structure.

Parameters:
name - the name of the field
Returns:
the field structure or null if the field does not exist

getFieldPositions

public float[] getFieldPositions(String name)
Gets the field box positions in the document. The return is an array of float multiple of 5. For each of this groups the values are: [page, llx, lly, urx, ury].

Parameters:
name - the field name
Returns:
the positions or null if field does not exist

removeRefFromArray

private int removeRefFromArray(PdfArray array,
                               PdfObject refo)

removeFieldsFromPage

public boolean removeFieldsFromPage(int page)
Removes all the fields from page.

Parameters:
page - the page to remove the fields from
Returns:
true if any field was removed, false otherwise

removeField

public boolean removeField(String name,
                           int page)
Removes a field from the document. If page equals -1 all the fields with this name are removed from the document otherwise only the fields in that particular page are removed.

Parameters:
name - the field name
page - the page to remove the field from or -1 to remove it from all the pages
Returns:
true if the field exists, false otherwise

removeField

public boolean removeField(String name)
Removes a field from the document.

Parameters:
name - the field name
Returns:
true if the field exists, false otherwise

isGenerateAppearances

public boolean isGenerateAppearances()
Gets the property generateAppearances.

Returns:
the property generateAppearances

setGenerateAppearances

public void setGenerateAppearances(boolean generateAppearances)
Sets the option to generate appearances. Not generating apperances will speed-up form filling but the results can be unexpected in Acrobat. Don't use it unless your environment is well controlled. The default is true.

Parameters:
generateAppearances - the option to generate appearances