|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.pdf2.FormElement
org.faceless.pdf2.FormText
public final class 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_BARCODE
Represents the "barcode" type of text field available in XFA. |
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 |
isDoNotSpellCheck()
Deprecated. call isSpellCheck instead |
boolean |
isScrollable()
Get whether this field is scrollable or not - horizontally for for single line text fields, vertically for multi-line |
boolean |
isSpellCheck()
Return the value of the "spell check" flag, as set by setSpellCheck(boolean) |
void |
rebuild()
Cause the annotations to be rebuilt. |
void |
setDefaultValue(String value)
Set the default value of this field - the value it will reset to if a PDFAction.formReset() occurs. |
void |
setDoNotSpellCheck(boolean check)
Deprecated. call setSpellCheck instead |
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 |
setSpellCheck(boolean spellcheck)
Set the "spell check" flag on the field, which controls whether Acrobat will run its spell-checker on the field. |
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. |
String |
toString()
|
Methods inherited from class org.faceless.pdf2.FormElement |
---|
addPropertyChangeListener, duplicate, flatten, getAction, getAnnotation, getAnnotations, getDescription, getForm, isReadOnly, isRequired, isSubmitted, removePropertyChangeListener, setAction, setDescription, setReadOnly, setRequired, setSubmitted |
Methods inherited from class java.lang.Object |
---|
equals, 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
public static final int TYPE_BARCODE
getType()
.
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 setSpellCheck(boolean spellcheck)
spellcheck
- whether to spell-check the field (true, the default) or not (false)public boolean isSpellCheck()
setSpellCheck(boolean)
public void setNumberOfCombs(int numcombs)
Set the number of "Combs" in this field. A comb can be used when a fixed number of digits are to be entered into the field - the digits will be spaced evenly along the field, so that they appear to be entered into a box. This is an Acrobat 6.0 feature, and although it can be used with documents intended for earlier versions of the viewers, if the text is changed in an earlier viewer the "comb" will be lost.
A field cannot have a maximum length and a number of combs at the same time,
so setting this will also call setMaxLength(0)
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)
setNumberOfCombs(0)
maxlen
- the maximum number of characters in the field, or zero for no maximumpublic int getMaxLength()
public void rebuild()
FormElement
rebuild
in class FormElement
public void setDoNotSpellCheck(boolean check)
public boolean isDoNotSpellCheck()
public String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |