|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.PDFObject
org.faceless.pdf2.PDFMap
org.faceless.pdf2.Form
The Form class represents the interactive Form that may be included as part of a PDF document. This form can be filled out by users and then eventually submitted for processing in the same way as an HTML form. Unlike HTML, a PDF document may only have one form.
A form contains zero or more FormElement
objects which you can
access via the getElements()
method. Each form element usually has
one or more visual representation on the page - a WidgetAnnotation
.
These annotation can be accessed by the FormElement.getAnnotations()
method. Each element in the form is stored under a name, which is used to
reference the element and must be unique.
The name may be a simple string, like "Element1"
, or it may be
a compound name, with fields separated with dots, for example
"Employee.Address.City"
. Simple and Compound names must not
collide - for example, it would be illegal to have elements called
"Country.Capital" and "Country" in the same document.
Note that using interactive forms requires the "Extended Edition" of the library - although the classes are supplied with the package an "Extended Edition" license must be purchased to activate this functionality.
PDF.getForm()
,
FormElement
Method Summary | |
void |
addElement(String name,
FormElement element)
Add an element to the form. |
void |
clear()
Remove all the elements from the form |
boolean |
equals(Object o)
|
void |
flatten()
Flatten the entire form. |
FormElement |
getElement(String name)
Return the specified element from the form. |
Map |
getElements()
Return a map of all the elements in the form. |
String |
getName(FormElement element)
Given a FormElement , return the name by which
this element is stored in the form, or null if
it doesn't exist in this form. |
FormElement |
removeElement(String name)
Remove the specified element from the form, if it exists. |
void |
renameAllElements(String prefix,
String suffix)
Rename all the elements in the form by adding a prefix and/or suffix to their names. |
void |
renameElement(String fromname,
String toname)
Rename an element in the form. |
void |
setBackgroundStyle(PDFStyle style)
Set the default background style for all new elements added to the form. |
void |
setTextStyle(PDFStyle style)
Set the default text style for all new elements added to the form. |
String |
toString()
|
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
public Map getElements()
String
representing the name of the
element, and the corresponding value is the FormElement
. The
returned map can be modified to add or remove elements from the form.
The fields are stored in the order they are added to the Map.
Map
containing all the form elementspublic void addElement(String name, FormElement element)
Add an element to the form. Although a form can contain as many elements
as you like, currently only a single signature with a state of
FormSignature.STATE_PENDING
can be added to each document.
This method is identical to calling:
form.getElements().put(name, element);
name
- the name of the form elementelement
- the element to add to the form
IllegalStateException
- if the element already exists in the formpublic FormElement getElement(String name)
FormElement element = form.getElements().get(name);
name
- the name of the form element
null
if it doesn't existpublic FormElement removeElement(String name)
FormElement element = form.getElements().remove(name);
name
- the name of the form element to remove
null
if it didn't existpublic void renameElement(String fromname, String toname)
IllegalArgumentException
is thrown. Since 2.0 the element keeps the same ordering in the form.
fromname
- the original name of the form elementtoname
- the new name of the form element
IllegalArgumentException
- if the specified element does not existpublic void renameAllElements(String prefix, String suffix)
prefix
- the prefix to add to all element names - may be null
suffix
- the suffix to add to all element names - may be null
public void clear()
public String getName(FormElement element)
FormElement
, return the name by which
this element is stored in the form, or null
if
it doesn't exist in this form.
null
if it's not in the Formpublic void setBackgroundStyle(PDFStyle style)
WidgetAnnotation.setBackgroundStyle(org.faceless.pdf2.PDFStyle)
method in the WidgetAnnotation
class. The default is a white
background with a plain black border
style
- the default back style for new form elementsWidgetAnnotation.setBackgroundStyle(org.faceless.pdf2.PDFStyle)
public void setTextStyle(PDFStyle style)
style
- the default text style for new form elementsWidgetAnnotation.setTextStyle(org.faceless.pdf2.PDFStyle)
public void flatten()
Flatten the entire form. Calls FormElement.flatten()
on every element in
the form and then delete it, so only the visible appearance of the form remains.
Provided the user is not going to edit the values in the form, flattening a form
before rendering is an extremely effective way to reduce the size of the document.
Note that if you use JavaScript to format the field before display, this will
not be taken into used when the field is flattened. Only the exact
value returned by FormElement.getValue()
will be used.
public String toString()
public boolean equals(Object o)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |