|
||||||||||
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.FormElement
org.faceless.pdf2.FormText
A type of form element representing a Text Field. Text fields may be single or multi-line, or may represent a password or (in Acrobat 5.0) a filename.
Here's an example showing how to create a new single-line text field in a form.
Form form = pdf.getForm(); FormText text = new FormText(pdf.getLastPage(), 100,100,300,120); form.addElement("AccountNumber", text);
And here's how to extract the value from an existing text field in a form
Form form = pdf.getForm(); FormText text = (FormText)form.getElement("AccountNumber"); String account = text.getValue(); // May be null
To add validation to a field isn't difficult either - here's how to use two of the built-in JavaScript methods in Adobe Acrobat to limit the keypresses in the field to digits only, and to limit the final value to between 1930 and 1985.
FormText text = new FormText(pdf.getLastPage(), 100,100,300,120); WidgetAnnotation annot = text.getAnnotation(0); PDFAction onkey = PDFAction.formJavaScript("AFNumber_Keystroke(0,1,1,0,'',true);"); PDFAction onchg = PDFAction.formJavaScript("AFRange_Validate(true,1930,true,1985);"); annot.setAction(Event.KEYPRESS, onkey); annot.setAction(Event.CHANGE, onchg);
Field Summary | |
static int |
TYPE_FILESELECT
Parameter to setType(int) to create a text box for selecting a file |
static int |
TYPE_MULTILINE
Parameter to setType(int) to create a multiline text box |
static int |
TYPE_NORMAL
Parameter to setType(int) to create a normal text box |
static int |
TYPE_PASSWORD
Parameter to setType(int) to create a text box for entering password |
Constructor Summary | |
FormText()
Create a new FormText object. |
|
FormText(PDFPage page,
float x1,
float y1,
float x2,
float y2)
Create a new FormText object, and add an annotation at the specified location. |
Method Summary | |
WidgetAnnotation |
addAnnotation(PDFPage page,
float x1,
float y1,
float x2,
float y2)
Add an annotation for this element at the specified location on the page |
String |
getDefaultValue()
Return the default value of this field - the value it will reset to if a PDFAction.formReset() occurs. |
int |
getMaxLength()
Return the maximum size of the text field, or zero if there is no maximum |
int |
getNumberOfCombs()
Return the number of combs in this field as set by setNumberOfCombs(int) ,
or 0 if the field is not combed |
int |
getType()
Get the type of field this is, as set by setType(int) |
String |
getValue()
Get the value of this field if set, or null |
boolean |
isScrollable()
Get whether this field is scrollable or not - horizontally for for single line text fields, vertically for multi-line |
void |
setDefaultValue(String value)
Set the default value of this field - the value it will reset to if a PDFAction.formReset() occurs. |
void |
setMaxLength(int maxlen)
Set the maximum length of the field. |
void |
setNumberOfCombs(int numcombs)
Set the number of "Combs" in this field. |
void |
setScrollable(boolean scrollable)
Set whether the field can be scrolled (horizontally for single line fields, vertically for multi-line fields) to enter more text than can be displayed in the form. |
void |
setType(int type)
Set the type of field - one of TYPE_NORMAL , TYPE_PASSWORD ,
TYPE_MULTILINE or TYPE_FILESELECT |
void |
setValue(String value)
Set the value of this field. |
Methods inherited from class org.faceless.pdf2.FormElement |
equals, flatten, getAction, getAnnotation, getAnnotations, getDescription, getForm, isReadOnly, isRequired, isSubmitted, setAction, setDescription, setReadOnly, setRequired, setSubmitted, toString |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int TYPE_NORMAL
setType(int)
to create a normal text box
public static final int TYPE_MULTILINE
setType(int)
to create a multiline text box
public static final int TYPE_PASSWORD
setType(int)
to create a text box for entering password
public static final int TYPE_FILESELECT
setType(int)
to create a text box for selecting a file
Constructor Detail |
public FormText()
addAnnotation(org.faceless.pdf2.PDFPage, float, float, float, float)
method.
public FormText(PDFPage page, float x1, float y1, float x2, float y2)
FormText text = new FormText(); text.addAnnotation(page, x1, y1, x2, y2);
page
- the PDFPage
to place the annotation onx1
- the left-most X co-ordinate of the annotationy1
- the bottom-most Y co-ordinate of the annotationx2
- the right-most X co-ordinate of the annotationy2
- the top-most Y co-ordinate of the annotationMethod Detail |
public WidgetAnnotation addAnnotation(PDFPage page, float x1, float y1, float x2, float y2)
page
- the PDFPage
to place the annotation onx1
- the left-most X co-ordinate of the annotationy1
- the bottom-most Y co-ordinate of the annotationx2
- the right-most X co-ordinate of the annotationy2
- the top-most Y co-ordinate of the annotationpublic void setType(int type)
TYPE_NORMAL
, TYPE_PASSWORD
,
TYPE_MULTILINE
or TYPE_FILESELECT
public int getType()
setType(int)
public void setValue(String value)
IllegalArgumentException
- if the field is a TYPE_PASSWORD
,
the value is longer than getMaxLength()
or it contains newlines when
the field is not TYPE_MULTILINE
public void setDefaultValue(String value)
PDFAction.formReset()
occurs.
IllegalArgumentException
- if the field is a TYPE_PASSWORD
,
the value is longer than getMaxLength()
or it contains newlines when
the field is not TYPE_MULTILINE
public String getValue()
null if not.
- Specified by:
getValue
in class FormElement
public String getDefaultValue()
PDFAction.formReset()
occurs.
public void setScrollable(boolean scrollable)
true
.
isScrollable()
public boolean isScrollable()
setScrollable(boolean)
public void setNumberOfCombs(int numcombs)
numcombs
- the number of combs in this field.public int getNumberOfCombs()
setNumberOfCombs(int)
,
or 0 if the field is not combed
public void setMaxLength(int maxlen)
maxlen
- the maximum number of characters in the field, or zero for no maximumpublic int getMaxLength()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |