public class PDFForm
extends java.lang.Object
PDFForm
represents a PDF Form.
The PDFForm
class defines methods to get and set properties of PDF
AcroForm. And definitions for enumerate PDFFormField
and
PDFFormControl
objects.
It can be constructed by the following way:
Example:
PDFForm form = PDFDocument.loadForm();
PDFDocument
Modifier and Type | Field and Description |
---|---|
static int |
ALIGNMENT_CENTER
Center alignment.
|
static int |
ALIGNMENT_LEFT
Left alignment.
|
static int |
ALIGNMENT_RIGHT
Right alignment.
|
Modifier and Type | Method and Description |
---|---|
int |
countFields(java.lang.String filter)
Get count of fields satisfying a name filter in the form.
|
void |
exportToFDF(FileHandler fdfFile)
Export data in the form to a FDF document.
|
void |
exportToXML(FileHandler xmlFile)
Export the form data to a XML file.
|
int |
getAlignment()
Retrieve alignment property of the form.
|
PDFFormControl |
getControlAtDevicePos(PDFPage page,
Matrix matrix,
java.awt.Point point,
float tolerance,
int typeFilter)
Retrieve a form control which locates at a specific device position in the
form.
|
PDFFormControl |
getControlAtPos(PDFPage page,
java.awt.geom.Point2D.Float point,
float tolerance,
int typeFilter)
Retrieve a form control at a specific position in the form.
|
DefaultAppearance |
getDefaultAppearance()
Retrieve a default appearance of the form.
|
PDFDocument |
getDocument()
Retrieve a PDF document which owns the form.
|
PDFFormField |
getField(java.lang.String filter,
int index)
Get the fields with specified filter and index.
|
java.lang.String[] |
getFieldsInCalculationOrder()
Get fields in the form in calculation order.
|
long |
getHandle()
Get the form handle.
|
void |
importFromFDF(FileHandler fdfFile)
Import data in FDF document to fill the form.
|
void |
importFromXML(FileHandler xmlFile)
Import the form data from a XML file.
|
boolean |
needConstructAppearances()
Check whether need to construct appearance property of the form or not.
|
boolean |
renameField(java.lang.String fieldName,
java.lang.String newFieldName)
Rename a field to a new name.
|
void |
reset(java.lang.String[] fieldNames,
boolean bInclude)
Reset data in fields to their default value.
|
void |
setAlignment(int alignment)
Set alignment property of current form, as a document-wide default value.
|
void |
setConstructAppearancesFlag(boolean needConstruct)
Set a flag that specifies whether to construct appearances when loading
form controls.
|
void |
setDefaultAppearance(DefaultAppearance appearance)
Set default appearance of the form.
|
boolean |
setFieldsInCalculationOrder(java.lang.String[] fieldNames)
Set fields in calculation order in the form.
|
boolean |
validateFieldName(java.lang.String fieldName,
int fieldType)
Check whether a name is valid for specified type of field in the form.
|
public static final int ALIGNMENT_LEFT
public static final int ALIGNMENT_CENTER
public static final int ALIGNMENT_RIGHT
public long getHandle()
public PDFDocument getDocument()
PDFDocument
object.PDFDocument
public int countFields(java.lang.String filter) throws PDFException
It will count all fields if parameter filter
is
null
.
filter
- A String
object which partially matches with the name of fields.
It can be null
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public PDFFormField getField(java.lang.String filter, int index) throws PDFException
It will get a form field from all fields with specific index if
filter
is null
.
filter
- A String
object which partially matches with the name of
fields. It can be null
. For example, text1 will
match text1.0, text1.2.0, etc. but text1 will not match test10
or test11.1..index
- Specify which field to retrieve information in the filtered
results.PDFFormField
object to receive a new PDF form
field object.null
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
PDFFormField
public PDFFormControl getControlAtPos(PDFPage page, java.awt.geom.Point2D.Float point, float tolerance, int typeFilter) throws PDFException
page
- Which is a PDFPage
object.point
- A Point2D.Float
object that specifies the position in
device.tolerance
- Which specifies the offset tolerance of the search.typeFilter
- Which specifies the type of form control to search. Please
refer to constant definitions
PDFFormField.TYPE_XXX
and this should be one of these constants. If it is
PDFFormField.TYPE_UNKNOWN
, the first form
control locates at specific position in a page will be
retrieved.PDFFormControl
object to receive form control at a
specific device position in a form.null
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
PDFPage
,
PDFFormControl
public PDFFormControl getControlAtDevicePos(PDFPage page, Matrix matrix, java.awt.Point point, float tolerance, int typeFilter) throws PDFException
page
- Which is a PDFPage
object.matrix
- Which specifies the transform matrix returned by function
PDFPage.getDisplayMatrix(int,int,int,int,int)
.point
- A Point
object that specifies the position in
device.tolerance
- Which specifies the offset tolerance of the search.typeFilter
- Which specifies the type of form control to search. Please
refer to constant definitions
PDFFormField.TYPE_XXX
and this should be one of these constants. If it is
PDFFormField.TYPE_UNKNOWN
, the first form
control locates at specific position in a page will be retrieved.
PDFFormControl
object to receive form control at a
specific device position in a form.null
.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
PDFFormControl
,
PDFPage
public DefaultAppearance getDefaultAppearance() throws PDFException
DefaultAppearance
object to receive the default
appearance of form.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
DefaultAppearance
public int getAlignment() throws PDFException
PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public boolean needConstructAppearances() throws PDFException
boolean
value that specifies whether to
construct appearances when load form controls. true
if need, false
if not.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public boolean validateFieldName(java.lang.String fieldName, int fieldType) throws PDFException
fieldName
- Which represents the name of a form fieldfieldType
- Which specifies a field type this name is intended for. Please
refer to constant definitions
PDFFormField.TYPE_XXX
and this should be one of these constants.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public java.lang.String[] getFieldsInCalculationOrder() throws PDFException
String
objects array which is an array to hold field names
in order.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void reset(java.lang.String[] fieldNames, boolean bInclude) throws PDFException
fieldNames
- A String
objects array whose elements are field names to
include or exclude. if it is null, The function will reset
whole form according to parameter bInclude
;bInclude
- Specifies whether to include the fields in the resetting.
true
if include, false
if exclude.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void setDefaultAppearance(DefaultAppearance appearance) throws PDFException
appearance
- A DefaultAppearance
object to receives the
default appearance of the specified fields.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
DefaultAppearance
public void setAlignment(int alignment) throws PDFException
Alignment is a property of variable text. And it's only useful for text field and list box,
which may contain variable text as their content.
If a specific text field or list box has its own alignment value, the document-wide default one will be ignore;
otherwise, the document-wide default one will be used for the specific text field or list box.
alignment
- The new default alignment type of variable text. It should be one of the
followings:
PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void setConstructAppearancesFlag(boolean needConstruct) throws PDFException
needConstruct
- A boolean
value that specifies whether to
construct appearances when load form controls.
true
if need, false
if not.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public boolean renameField(java.lang.String fieldName, java.lang.String newFieldName) throws PDFException
fieldName
- Which represents the name of a form field.newFieldName
- Which represents the new name of a form field.true
if renamed successfully, else return
false
for not found the specified field.PDFException
- If newFieldName is same with an existing one and it's type is
different with the one specified by fieldName the field
specified by fieldName, it will throw a
PDFException.ERRCODE_CONFLICT
exception.
For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public boolean setFieldsInCalculationOrder(java.lang.String[] fieldNames) throws PDFException
fieldNames
- A String
objects array which represents an array
consisting of the field names to form a new calculation order.true
if set successfully, else return
false
for failure.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
public void exportToFDF(FileHandler fdfFile) throws PDFException
FileHandler's file mode should be FILEMODE_WRITE or FILEMODE_TRUNCATE, if not, PDFException.ERRCODE_ERROR will be thrown.
fdfFile
- Handle to a FileHandler
object which is the
output FDF file.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
FileHandler
public void importFromFDF(FileHandler fdfFile) throws PDFException
FileHandler's file mode should be FILEMODE_READONLY, if not, PDFException.ERRCODE_ERROR will be thrown.
fdfFile
- Handle to a FileHandler
object which is the input
FDF file.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
FileHandler
public void exportToXML(FileHandler xmlFile) throws PDFException
FileHandler's file mode should be FILEMODE_WRITE or FILEMODE_TRUNCATE, if not, PDFException.ERRCODE_ERROR will be thrown.
xmlFile
- Handle to a FileHandler
object which is a Path of
PDF interactive form. It should be valid.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
FileHandler
public void importFromXML(FileHandler xmlFile) throws PDFException
FileHandler's file mode should be FILEMODE_READONLY, if not, PDFException.ERRCODE_ERROR will be thrown.
xmlFile
- Handle to a FileHandler
object which is a Path of
PDF interactive form. It should be valid.PDFException
- For more exception information please see definitions
PDFException.ERRCODE_XXX
.PDFException
,
FileHandler