Class PDButton
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.interactive.form.PDField
-
- org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField
-
- org.apache.pdfbox.pdmodel.interactive.form.PDButton
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDCheckBox,PDPushButton,PDRadioButton
public abstract class PDButton extends PDTerminalField
A button field represents an interactive control on the screen that the user can manipulate with the mouse.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intFLAG_PUSHBUTTONA Ff flag.(package private) static intFLAG_RADIOA Ff flag.(package private) static intFLAG_RADIOS_IN_UNISONA Ff flag.
-
Constructor Summary
Constructors Constructor Description PDButton(PDAcroForm acroForm)PDButton(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcheckValue(java.lang.String value)Checks value.(package private) voidconstructAppearances()Constructs appearance streams and appearance dictionaries for all widget annotations.java.lang.StringgetDefaultValue()Returns the default value, if any.java.util.List<java.lang.String>getExportValues()This will get the (optional) export values.private java.lang.StringgetOnValue(int index)private java.lang.StringgetOnValueForWidget(PDAnnotationWidget widget)java.util.Set<java.lang.String>getOnValues()Get the values to set individual buttons within a group to the on state.java.lang.StringgetValue()Returns the selected value.java.lang.StringgetValueAsString()Returns a string representation of the "V" entry, or an empty string.booleanisPushButton()Determines if push button bit is set.booleanisRadioButton()Determines if radio button bit is set.voidsetDefaultValue(java.lang.String value)Sets the default value.voidsetExportValues(java.util.List<java.lang.String> values)This will set the export values.voidsetValue(int index)Set the selected option given its index, and try to update the visual appearance.voidsetValue(java.lang.String value)Set the selected option given its name, and try to update the visual appearance.private voidupdateByOption(java.lang.String value)private voidupdateByValue(java.lang.String value)-
Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField
applyChange, exportFDF, getFieldFlags, getFieldType, getWidgets, importFDF, setActions, setWidgets
-
Methods inherited from class org.apache.pdfbox.pdmodel.interactive.form.PDField
findKid, fromDictionary, getAcroForm, getActions, getAlternateFieldName, getCOSObject, getFullyQualifiedName, getInheritableAttribute, getMappingName, getParent, getPartialName, isNoExport, isReadOnly, isRequired, setAlternateFieldName, setFieldFlags, setMappingName, setNoExport, setPartialName, setReadOnly, setRequired, toString
-
-
-
-
Field Detail
-
FLAG_RADIO
static final int FLAG_RADIO
A Ff flag. If set, the field is a set of radio buttons- See Also:
- Constant Field Values
-
FLAG_PUSHBUTTON
static final int FLAG_PUSHBUTTON
A Ff flag. If set, the field is a pushbutton.- See Also:
- Constant Field Values
-
FLAG_RADIOS_IN_UNISON
static final int FLAG_RADIOS_IN_UNISON
A Ff flag. If set, radio buttons individual fields, using the same value for the on state will turn on and off in unison.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PDButton
PDButton(PDAcroForm acroForm)
- Parameters:
acroForm- The acroform.- See Also:
PDField(PDAcroForm)
-
PDButton
PDButton(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
Constructor.- Parameters:
acroForm- The form that this field is part of.field- the PDF object to represent as a field.parent- the parent node of the node
-
-
Method Detail
-
isPushButton
public boolean isPushButton()
Determines if push button bit is set.- Returns:
- true if type of button field is a push button.
-
isRadioButton
public boolean isRadioButton()
Determines if radio button bit is set.- Returns:
- true if type of button field is a radio button.
-
getValue
public java.lang.String getValue()
Returns the selected value.Off is the default value which will also be returned if the value hasn't been set at all.
- Returns:
- A non-null string.
-
setValue
public void setValue(java.lang.String value) throws java.io.IOExceptionSet the selected option given its name, and try to update the visual appearance.
-
setValue
public void setValue(int index) throws java.io.IOExceptionSet the selected option given its index, and try to update the visual appearance. NOTE: this method is only usable if there are export values and used for radio buttons with FLAG_RADIOS_IN_UNISON not set.- Parameters:
index- index of option to be selected- Throws:
java.io.IOException- if the value could not be setjava.lang.IllegalArgumentException- if the index provided is not a valid index.
-
getDefaultValue
public java.lang.String getDefaultValue()
Returns the default value, if any.- Returns:
- A non-null string.
-
setDefaultValue
public void setDefaultValue(java.lang.String value)
Sets the default value.- Parameters:
value- Name of option to select- Throws:
java.lang.IllegalArgumentException- if the value is not a valid option.
-
getValueAsString
public java.lang.String getValueAsString()
Description copied from class:PDFieldReturns a string representation of the "V" entry, or an empty string.- Specified by:
getValueAsStringin classPDField- Returns:
- The list of widget annotations.
-
getExportValues
public java.util.List<java.lang.String> getExportValues()
This will get the (optional) export values.The export values are defined in the field dictionaries /Opt key.
The option values are used to define the export values for the field to
- hold values in non-Latin writing systems as name objects, which represent the field value, are limited to PDFDocEncoding
- allow radio buttons having the same export value to be handled independently
- Returns:
- List containing all possible export values. If there is no /Opt entry an empty list will be returned.
- See Also:
getOnValues()
-
setExportValues
public void setExportValues(java.util.List<java.lang.String> values)
This will set the export values.- Parameters:
values- List containing all possible export values. Supplying null or an empty list will remove the Opt entry.- See Also:
getExportValues()
-
constructAppearances
void constructAppearances() throws java.io.IOExceptionDescription copied from class:PDTerminalFieldConstructs appearance streams and appearance dictionaries for all widget annotations. Subclasses should not call this method directly but viaPDTerminalField.applyChange().- Specified by:
constructAppearancesin classPDTerminalField- Throws:
java.io.IOException- if the appearance couldn't be generated
-
getOnValues
public java.util.Set<java.lang.String> getOnValues()
Get the values to set individual buttons within a group to the on state.The On value could be an arbitrary string as long as it is within the limitations of a PDF name object. The Off value shall always be 'Off'. If not set or not part of the normal appearance keys 'Off' is the default
- Returns:
- the potential values setting the check box to the On state. If an empty Set is returned there is no appearance definition.
-
getOnValue
private java.lang.String getOnValue(int index)
-
getOnValueForWidget
private java.lang.String getOnValueForWidget(PDAnnotationWidget widget)
-
checkValue
void checkValue(java.lang.String value)
Checks value.- Parameters:
value- Name of radio button to select- Throws:
java.lang.IllegalArgumentException- if the value is not a valid option.
-
updateByValue
private void updateByValue(java.lang.String value)
-
updateByOption
private void updateByOption(java.lang.String value)
-
-