Class AcroChoiceField
- java.lang.Object
-
- com.snowtide.pdf.forms.AcroChoiceField
-
- All Implemented Interfaces:
DocumentLocation,AcroFormField,FormField,Bounded
public class AcroChoiceField extends Object
Represents a multiple-choice form field in an interactive AcroForm.
getValue()will return the 'export value' set on the field being represented; this is the name of the option that was selected by the user. The display value of that option (a user-friendly representation of the export value) can be retrieved using thegetDisplayValue(String)function.If
allowsMultipleChoices()returns true,AcroFormField.getValue()may return aString[]instance containing export values, one for each of the options selected by the user. These values may also be used as parameters into thegetDisplayValue(String)function.Note that if
isEditable()returns true, the String returned byAcroFormField.getValue()may be user-entered text, and therefore would likely not have a corresponding display value provided bygetDisplayValue(String).In addition to the standard
AcroFormField.setValue(String)function,AcroChoiceFieldinstances provide asetValue(String[])function, enabling the value of a multiple-selection choice field possible.- Since:
- v2.1
- Version:
- ©2004-2025 Snowtide
-
-
Field Summary
Fields Modifier and Type Field Description static intCHOICE_TYPE_COMBOValue returned bygetWidgetType(), indicating that anAcroChoiceFieldis representing a drop-down combo box.static intCHOICE_TYPE_LISTValue returned bygetWidgetType()indicating that anAcroChoiceFieldis representing a list that can potentially allow multiple values to be selected.-
Fields inherited from interface com.snowtide.pdf.forms.AcroFormField
FIELD_TYPE_BUTTON, FIELD_TYPE_CHOICE, FIELD_TYPE_OTHER, FIELD_TYPE_SIGNATURE, FIELD_TYPE_TEXT
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowsMultipleChoices()Returns true if this choice field's widget allows multiple selections.Regionbounds()booleancanChangeValue()Always returns true.ObjectgetDefaultValue()Returns the default value to which the field reverts when a reset-form action is executed, as specified in the /DV entry in this field's PDF dictionary.StringgetDisplayValue(String exportValue)Returns the display value associated with the supplied export value.StringgetExportValue(String displayValue)StringgetFullName()Returns the fully-qualified name of this field, which should be unique within a PDF document form.StringgetLocalName()Returns the local name of the field, as specified in the /T entry in this field's PDF dictionary.StringgetMappingName()Returns the 'mapping name' of this field, as specified in the /TM entry in this field's PDF dictionary.StringgetName()Returns the canonical name of this field.MapgetOptions()Returns a Map containing all of the options offered by this choice field, using export values (strings that can be returned bygetValue()) as keys mapped to display values (strings that are returned bygetDisplayValue(String), given a valid export value).ObjectgetType()Returns the type of field, as specified in the /FT entry in this field's PDF dictionary.StringgetUIName()Returns the user-friendly name of this field, as specified in the /TU entry in this field's PDF dictionary.ObjectgetValue()Returns the value of this field, as specified in the /V entry in this field's PDF dictionary.intgetWidgetType()Returns eitherCHOICE_TYPE_COMBO(indicating that this choice widget is a dropdown, single-selection field), orCHOICE_TYPE_LIST, indicating that this choice widget is a multiple-row, possibly multiple-selection field).booleanhasValueChanged()Returns true only if this field's value has been changed since being loaded from the PDF document.booleanisEditable()Returns true if this field is user-editable, indicating that a user may set this field's value to a arbitrary character string.booleanisReadOnly()Returns true only if this field is designated as read-only.intpageNumber()This page number is 0-indexed, and may be used to retrieve aPageobject representing the page's content using theDocument#getPage(int)function.booleansetValue(String value)Updates this choice field's value so that the option corresponding with the single specified String is selected.booleansetValue(String[] values)Updates this choice field's value so that each of the options corresponding with the Strings in the specified array are selected.
-
-
-
Field Detail
-
CHOICE_TYPE_COMBO
public static final int CHOICE_TYPE_COMBO
Value returned bygetWidgetType(), indicating that anAcroChoiceFieldis representing a drop-down combo box.- See Also:
- Constant Field Values
-
CHOICE_TYPE_LIST
public static final int CHOICE_TYPE_LIST
Value returned bygetWidgetType()indicating that anAcroChoiceFieldis representing a list that can potentially allow multiple values to be selected.- See Also:
allowsMultipleChoices(), Constant Field Values
-
-
Method Detail
-
setValue
public boolean setValue(String value) throws IllegalArgumentException
Updates this choice field's value so that the option corresponding with the single specified String is selected.- Specified by:
setValuein interfaceAcroFormField- Returns:
- true if this field's value changes as a result of this call, false otherwise
- Throws:
IllegalArgumentException- if the specified value is not an allowable value. To be allowable, the specified value must appear as a key in the Map returned bygetExportValue(String), or, if this fieldis editable, then any non-null String value is allowable.- Since:
- v2.1
-
setValue
public boolean setValue(String[] values) throws IllegalArgumentException
Updates this choice field's value so that each of the options corresponding with the Strings in the specified array are selected.- Returns:
- true if this field's value changes as a result of this call, false otherwise
- Throws:
IllegalArgumentException- if this field does notallow multiple choicesor if any String in the provided array is not an allowable value. To be allowable, each String in the given array must be non-null, and must appear as a key in the Map returned bygetExportValue(String).- Since:
- v2.1
-
canChangeValue
public boolean canChangeValue()
Always returns true.- Specified by:
canChangeValuein interfaceAcroFormField
-
getDisplayValue
public String getDisplayValue(String exportValue)
Returns the display value associated with the supplied export value.
-
getOptions
public Map getOptions()
Returns a Map containing all of the options offered by this choice field, using export values (strings that can be returned bygetValue()) as keys mapped to display values (strings that are returned bygetDisplayValue(String), given a valid export value).
-
isEditable
public boolean isEditable()
Returns true if this field is user-editable, indicating that a user may set this field's value to a arbitrary character string. If this happens, it is likely that this field's value will not correspond to a display value viagetDisplayValue(String).
-
getWidgetType
public int getWidgetType()
Returns eitherCHOICE_TYPE_COMBO(indicating that this choice widget is a dropdown, single-selection field), orCHOICE_TYPE_LIST, indicating that this choice widget is a multiple-row, possibly multiple-selection field).
-
allowsMultipleChoices
public boolean allowsMultipleChoices()
Returns true if this choice field's widget allows multiple selections. This will only be true if
getWidgetType()returnsCHOICE_TYPE_LIST.This is important in that if this choice field's widget allows multiple selections, and multiple options have been selected, then the
getValue()function will return an array of the selected options' values, instead of a simple String.
-
pageNumber
public int pageNumber()
Description copied from interface:DocumentLocationThis page number is 0-indexed, and may be used to retrieve aPageobject representing the page's content using theDocument.getPage(int)function.If a page number is not available for some reason, then this method will return -1.
- Specified by:
pageNumberin interfaceDocumentLocation
-
isReadOnly
public boolean isReadOnly()
Description copied from interface:AcroFormFieldReturns true only if this field is designated as read-only. Note that this is just a hint, provided for the benefit of end-user tools. PDFxStream does not enforce the read-only state of a form field; i.e. it will allow a field's value to be set even if it is designated as read-only.- Specified by:
isReadOnlyin interfaceAcroFormField
-
getDefaultValue
public Object getDefaultValue()
Description copied from interface:AcroFormFieldReturns the default value to which the field reverts when a reset-form action is executed, as specified in the /DV entry in this field's PDF dictionary. The type of the returned object will be the same as the type of object returned by theAcroFormField.getValue()function, and depends upon the type of this field.- Specified by:
getDefaultValuein interfaceAcroFormField
-
getFullName
public String getFullName()
Description copied from interface:AcroFormFieldReturns the fully-qualified name of this field, which should be unique within a PDF document form. Details of how full names are constructed are specified in Section 8.6.2 (Field Names) of the PDF Document Specification.
It suffices to say here that form fields in an interactive AcroForm are defined in a hierarchical manner, and that their
local namesare used to derive a period-delimited full name that guarantees each name's uniqueness within the parent AcroForm.- Specified by:
getFullNamein interfaceAcroFormField
-
getLocalName
public String getLocalName()
Description copied from interface:AcroFormFieldReturns the local name of the field, as specified in the /T entry in this field's PDF dictionary. This name is also used as the value returned by theFormField.getName()implementation.- Specified by:
getLocalNamein interfaceAcroFormField
-
getMappingName
public String getMappingName()
Description copied from interface:AcroFormFieldReturns the 'mapping name' of this field, as specified in the /TM entry in this field's PDF dictionary. The mapping name is used to identify the field in exported form data formats. This function can return null if no mapping name is defined.- Specified by:
getMappingNamein interfaceAcroFormField
-
getName
public String getName()
Description copied from interface:FormFieldReturns the canonical name of this field. Only oneFormFieldinstance with a particular name should be available from aForminstance.
-
getType
public Object getType()
Description copied from interface:AcroFormFieldReturns the type of field, as specified in the /FT entry in this field's PDF dictionary. This is an indication of the subtype of this AcroFormField instance:- If the return value is
FIELD_TYPE_BUTTON, then this AcroFormField is an instance ofAcroButtonField - If the return value is
FIELD_TYPE_TEXT, then this AcroFormField is an instance ofAcroTextField - If the return value is
FIELD_TYPE_CHOICE, then this AcroFormField is an instance ofAcroChoiceField - If the return value is
FIELD_TYPE_SIGNATURE, then this AcroFormField is an instance ofAcroSignatureField - If the return value is
FIELD_TYPE_OTHER, then this AcroFormField has no specific concrete implementation. This case is reserved for form fields with new type indicators that may be introduced by Adobe in the future.
- Specified by:
getTypein interfaceAcroFormField
- If the return value is
-
hasValueChanged
public boolean hasValueChanged()
Description copied from interface:AcroFormFieldReturns true only if this field's value has been changed since being loaded from the PDF document.- Specified by:
hasValueChangedin interfaceAcroFormField
-
getUIName
public String getUIName()
Description copied from interface:AcroFormFieldReturns the user-friendly name of this field, as specified in the /TU entry in this field's PDF dictionary. This function can return null if no user-friendly field name is defined.
- Specified by:
getUINamein interfaceAcroFormField- Specified by:
getUINamein interfaceFormField
-
getValue
public Object getValue()
Description copied from interface:AcroFormFieldReturns the value of this field, as specified in the /V entry in this field's PDF dictionary. The type of the returned object depends upon the type of this field.- Specified by:
getValuein interfaceAcroFormField- Specified by:
getValuein interfaceFormField
-
-