public class Field
extends java.lang.Object
for(FieldIterator itr = doc.getFieldIterator(); itr.hasNext();) {
Field current=(Field)(itr.next());
System.out.println("Field name: " + current.getName());
System.out.println("Field partial name: " + current.getPartialName());
}
For a full sample, please refer to 'InteractiveForms' sample project.
To search field by name use FieldFind method. For example:
// Search for a specific field
FieldIterator itr = doc.fieldFind("employee.name.first");
if (itr.hasNext()) System.out.println("Field search for " + ((Field)(itr.next())).getName() + " was successful");
else System.out.println("Field search failed");
If a given field name was not found or if the end of the field list
was reached the iterator HasNext() will return false.
If you have a valid iterator you can access the Field using Current() method. For example:
Field field = itr.Current();
Using Flatten(...) method it is possible to merge field
appearances with the page content. Form 'flattening' refers to the
operation that changes active form fields into a static area that is
part of the PDF document, just like the other text and images in
the document. A completely flattened PDF form does not have any
widget annotations or interactive fields.Modifier and Type | Field and Description |
---|---|
static int |
e_action_trigger_calculate
Triggered when field is recalculated due to a change in another field
|
static int |
e_action_trigger_format
Triggered before a field value is displayed.
|
static int |
e_action_trigger_keystroke
Triggered when user modifies text, or selection, in a text, combo or list field
|
static int |
e_action_trigger_validate
Triggered when a field value is changed
|
static int |
e_button
Interactive forms support the following field types:
- Button fields represent interactive controls on the screen that the user can
manipulate with the mouse.
|
static int |
e_centered
The Constant e_centered.
|
static int |
e_check
The Constant e_check.
|
static int |
e_choice
The Constant e_choice.
|
static int |
e_comb
The Constant e_comb.
|
static int |
e_combo
The Constant e_combo.
|
static int |
e_commit_on_sel_change
The Constant e_commit_on_sel_change.
|
static int |
e_edit
The Constant e_edit.
|
static int |
e_file_select
The Constant e_file_select.
|
static int |
e_left_justified
The Constant e_left_justified.
|
static int |
e_multiline
The Constant e_multiline.
|
static int |
e_multiselect
The Constant e_multiselect.
|
static int |
e_no_export
The Constant e_no_export.
|
static int |
e_no_scroll
The Constant e_no_scroll.
|
static int |
e_no_spellcheck
The Constant e_no_spellcheck.
|
static int |
e_null
The Constant e_null.
|
static int |
e_password
The Constant e_password.
|
static int |
e_pushbutton_flag
The Constant e_pushbutton_flag.
|
static int |
e_radio
The Constant e_radio.
|
static int |
e_radio_flag
The Constant e_radio_flag.
|
static int |
e_radios_in_unison
The Constant e_radios_in_unison.
|
static int |
e_read_only
Flags specifying various characteristics of the fields.
|
static int |
e_required
The Constant e_required.
|
static int |
e_rich_text
The Constant e_rich_text.
|
static int |
e_right_justified
The Constant e_right_justified.
|
static int |
e_signature
The Constant e_signature.
|
static int |
e_sort
The Constant e_sort.
|
static int |
e_text
The Constant e_text.
|
static int |
e_toggle_to_off
The Constant e_toggle_to_off.
|
Constructor and Description |
---|
Field(Obj field_dict)
Construct a Field from a SDF dictionary representing a terminal field node.
|
Modifier and Type | Method and Description |
---|---|
static Field |
__Create(long impl,
java.lang.Object ref) |
long |
__GetHandle() |
java.lang.Object |
__GetRefHandle() |
void |
destroy()
Frees the native memory of the object.
|
void |
eraseAppearance()
Removes any appearances associated with the field.
|
Obj |
findInheritedAttribute(java.lang.String attrib)
Some of the Field attributes are designated as inheritable.
|
void |
flatten(Page page)
Flatten/Merge existing form field appearances with the page content and
remove widget annotation.
|
GState |
getDefaultAppearance()
Get the default graphics state that should be used in formatting the
text.
|
Obj |
getDefaultValue()
Get the default value.
|
java.lang.String |
getDefaultValueAsString()
Get the default value as string.
|
boolean |
getFlag(int flag)
Get the value of the given flag.
|
int |
getJustification()
Get the quadding (justification).
|
int |
getMaxLen()
Get the maximum length
|
java.lang.String |
getName()
Get the field name
|
java.lang.String |
getOpt(int opt_idx)
Get name of the option specified by the given index.
|
int |
getOptCount()
Get the number of options.
|
java.lang.String |
getPartialName()
Get the partial name.
|
Obj |
getSDFObj()
Get the SDFObj.
|
Obj |
getTriggerAction(int trigger)
Get the Action associated with the selected Field Trigger event.
|
int |
getType()
Get the field type.
|
Rect |
getUpdateRect()
Return the rectangle that should be refreshed after changing a field.
|
Obj |
getValue()
Get the field value.
|
boolean |
getValueAsBool()
Get the value as boolean.
|
java.lang.String |
getValueAsString()
Get the value as string.
|
boolean |
isAnnot()
Check if current field is an Annotation
|
boolean |
isValid()
Checks if current field is valid.
|
void |
refreshAppearance()
Regenerates the appearance stream for the Widget Annotation containing
variable text.
|
void |
rename(java.lang.String field_name)
Modify the field name.
|
void |
setFlag(int flag,
boolean value)
Set the value of given field flag.
|
void |
setJustification(int j)
Set the justification to be used in displaying the text field.
|
void |
setMaxLen(int max_len)
Set the maximum length of the field's text, in characters.
|
ViewChangeCollection |
setValue(boolean is_checked)
Set the boolean value.
|
ViewChangeCollection |
setValue(Obj value)
Set the value of the Field (i.e.
|
ViewChangeCollection |
setValue(java.lang.String value)
Set the string value.
|
Obj |
useSignatureHandler(long signature_handler_id)
Sets the signature handler to use for adding a signature to this field.
|
public static final int e_button
public static final int e_check
public static final int e_radio
public static final int e_text
public static final int e_choice
public static final int e_signature
public static final int e_null
public static final int e_action_trigger_keystroke
public static final int e_action_trigger_format
public static final int e_action_trigger_validate
public static final int e_action_trigger_calculate
public static final int e_read_only
public static final int e_required
public static final int e_no_export
public static final int e_pushbutton_flag
public static final int e_radio_flag
public static final int e_toggle_to_off
public static final int e_radios_in_unison
public static final int e_multiline
public static final int e_password
public static final int e_file_select
public static final int e_no_spellcheck
public static final int e_no_scroll
public static final int e_comb
public static final int e_rich_text
public static final int e_combo
public static final int e_edit
public static final int e_sort
public static final int e_multiselect
public static final int e_commit_on_sel_change
public static final int e_left_justified
public static final int e_centered
public static final int e_right_justified
public Field(Obj field_dict) throws PDFNetException
field_dict
- the field_dictPDFNetException
public void destroy() throws PDFNetException
PDFNetException
public boolean isValid() throws PDFNetException
PDFNetException
public Obj getTriggerAction(int trigger) throws PDFNetException
trigger
- the type of trigger event to getPDFNetException
public int getType() throws PDFNetException
PDFNetException
public Obj getValue() throws PDFNetException
PDFNetException
public java.lang.String getValueAsString() throws PDFNetException
PDFNetException
public boolean getValueAsBool() throws PDFNetException
PDFNetException
public ViewChangeCollection setValue(Obj value) throws PDFNetException
Note: in order to remove/erase the existing value use pass a SDF::Null object to SetValue().
Note: In PDF, Field's value is separate from its annotation (i.e. how the field appears on the page). After you modify Field's value you need to refresh Field's appearance using RefreshAppearance() method. Alternatively, you can delete "AP" entry from the Widget annotation and set "NeedAppearances" flag in AcroForm dictionary (i.e. doc.GetAcroForm().Put("NeedAppearances", Obj.CreateBool(true)); ) This will force viewer application to auto-generate new field appearances every time the document is opened. Yet another option is to generate a custom annotation appearance using ElementBuilder and ElementWriter and then set the "AP" entry in the widget dictionary to the new appearance stream. This functionality is useful in applications that need advanced control over how the form fields are rendered.
value
- the new valuePDFNetException
public ViewChangeCollection setValue(java.lang.String value) throws PDFNetException
value
- the new value as StringPDFNetException
public ViewChangeCollection setValue(boolean is_checked) throws PDFNetException
is_checked
- the new boolean valuePDFNetException
public void refreshAppearance() throws PDFNetException
Note: If this field contains text, and has been added to a rotated page, the text in the field may be rotated. If RefreshAppearance is called *after* the field is added to a rotated page, then any text will be rotated in the opposite direction of the page rotation. If this method is called *before* the field is added to any rotated page, then no counter rotation will be applied. If you wish to call RefreshAppearance on a field already added to a rotated page, but you don't want the text to be rotated, you can do one of the following; temporarily un-rotate the page, or, temporarily remove the "P" object from the field.
PDFNetException
public void eraseAppearance() throws PDFNetException
PDFNetException
public Obj getDefaultValue() throws PDFNetException
PDFNetException
public GState getDefaultAppearance() throws PDFNetException
PDFNetException
public java.lang.String getDefaultValueAsString() throws PDFNetException
PDFNetException
public java.lang.String getName() throws PDFNetException
PDFNetException
public java.lang.String getPartialName() throws PDFNetException
PDFNetException
public void rename(java.lang.String field_name) throws PDFNetException
field_name
- a string representing the fully qualified name of
the field (e.g. "employee.name.first").PDFNetException
public boolean isAnnot() throws PDFNetException
PDFNetException
public boolean getFlag(int flag) throws PDFNetException
flag
- the given flagPDFNetException
public void setFlag(int flag, boolean value) throws PDFNetException
Note: You can use this method to set the field as read-only. An alternative approach to set the field as read only is using Page.Flatten(...) method. Unlike Flatten(...), the result of SetFlag(...) can be programatically reversed.
flag
- the given field flagvalue
- the value of the field flagPDFNetException
public int getJustification() throws PDFNetException
PDFNetException
public void setJustification(int j) throws PDFNetException
j
- the new justificationPDFNetException
public void setMaxLen(int max_len) throws PDFNetException
Note: This method is specific to a text field.
max_len
- the new maximum lengthPDFNetException
public int getMaxLen() throws PDFNetException
Note: This method is specific to a text field.
PDFNetException
public void flatten(Page page) throws PDFNetException
Note: an alternative approach to set the field as read only is using Field.SetFlag(Field::e_read_only, true) method. Unlike Field.SetFlag(...), the result of Flatten() operation can not be programatically reversed.
page
- the page contentPDFNetException
public Obj findInheritedAttribute(java.lang.String attrib) throws PDFNetException
attrib
- the attributes to be foundPDFNetException
public Rect getUpdateRect()
public Obj getSDFObj() throws PDFNetException
PDFNetException
public Obj useSignatureHandler(long signature_handler_id) throws PDFNetException
signature_handler_id
- The unique id of the SignatureHandler to use for adding signature in this field.PDFNetException
public int getOptCount() throws PDFNetException
PDFNetException
public java.lang.String getOpt(int opt_idx) throws PDFNetException
Note: The index must be less than the value returned by GetOptCount().
PDFNetException
public static Field __Create(long impl, java.lang.Object ref) throws PDFNetException
PDFNetException
public long __GetHandle()
public java.lang.Object __GetRefHandle()