Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.interactive.form

public abstract Class PDButton

extends PDTerminalField
Class Inheritance
Known Direct Subclasses
org.apache.pdfbox.pdmodel.interactive.form.PDCheckBox, org.apache.pdfbox.pdmodel.interactive.form.PDPushButton, org.apache.pdfbox.pdmodel.interactive.form.PDRadioButton
Imports
org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSString, java.io.IOException, java.util.Collections, .LinkedHashSet, .List, .Set, org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget, .PDAppearanceDictionary, .PDAppearanceEntry

A button field represents an interactive control on the screen that the user can manipulate with the mouse.
Author
sug

Field Summary

Modifier and TypeField and Description
pack-priv static final int
FLAG_PUSHBUTTON

A Ff flag.

pack-priv static final int
FLAG_RADIO

A Ff flag.

pack-priv static final int

Constructor Summary

AccessConstructor and Description
pack-priv
PDButton(PDAcroForm
The acroform.
acroForm
)

pack-priv
PDButton(PDAcroForm
The form that this field is part of.
acroForm
,
COSDictionary
the PDF object to represent as a field.
field
,
PDNonTerminalField
the parent node of the node
parent
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
checkValue(String
Name of radio button to select
value
)

Checks value.

pack-priv void
constructAppearances()

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.constructAppearances.

Constructs appearance streams and appearance dictionaries for all widget annotations.

public String

Returns:

A non-null string.
getDefaultValue
()

Returns the default value, if any.

public List<String>

Returns:

List containing all possible export values. If there is no /Opt entry an empty list will be returned.
getExportValues
()

This will get the (optional) export values.

private String
getOnValue(int index)

private String
public Set<String>

Returns:

the potential values setting the check box to the On state. If an empty Set is returned there is no appearance definition.
getOnValues
()

Get the values to set individual buttons within a group to the on state.

public String

Returns:

A non-null string.
getValue
()

Returns the selected value.

public String
getValueAsString()

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDField.getValueAsString.

Returns a string representation of the "V" entry, or an empty string.

public boolean

Returns:

true if type of button field is a push button.
isPushButton
()

Determines if push button bit is set.

public boolean

Returns:

true if type of button field is a radio button.
isRadioButton
()

Determines if radio button bit is set.

public void
setDefaultValue(String
Name of option to select
value
)

Sets the default value.

public void
setExportValues(List<String>
List containing all possible export values. Supplying null or an empty list will remove the Opt entry.
values
)

This will set the export values.

public void
setValue(String
Name of option to select
value
)

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDField.setValue.

Set the selected option given its name, and try to update the visual appearance.

public void
setValue(int
index of option to be selected
index
)

Set the selected option given its index, and try to update the visual appearance.

private void
private void
Inherited from org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField:
applyChangeexportFDFgetFieldFlagsgetFieldTypegetWidgetsimportFDFsetActionssetWidgets

Field Detail

FLAG_PUSHBUTTONback to summary
pack-priv static final int FLAG_PUSHBUTTON

A Ff flag. If set, the field is a pushbutton.

FLAG_RADIOback to summary
pack-priv static final int FLAG_RADIO

A Ff flag. If set, the field is a set of radio buttons

FLAG_RADIOS_IN_UNISONback to summary
pack-priv 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.

Constructor Detail

PDButtonback to summary
pack-priv PDButton(PDAcroForm acroForm)
Parameters
acroForm:PDAcroForm

The acroform.

See Also
PDField#PDField(PDAcroForm)
PDButtonback to summary
pack-priv PDButton(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)

Constructor.

Parameters
acroForm:PDAcroForm

The form that this field is part of.

field:COSDictionary

the PDF object to represent as a field.

parent:PDNonTerminalField

the parent node of the node

Method Detail

checkValueback to summary
pack-priv void checkValue(String value)

Checks value.

Parameters
value:String

Name of radio button to select

Exceptions
IllegalArgumentException:
if the value is not a valid option.
constructAppearancesback to summary
pack-priv void constructAppearances() throws IOException

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.constructAppearances.

Doc from org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField.constructAppearances.

Constructs appearance streams and appearance dictionaries for all widget annotations. Subclasses should not call this method directly but via applyChange().

Annotations
@Override
Exceptions
IOException:
if the appearance couldn't be generated
getDefaultValueback to summary
public String getDefaultValue()

Returns the default value, if any.

Returns:String

A non-null string.

getExportValuesback to summary
public List<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<String>

List containing all possible export values. If there is no /Opt entry an empty list will be returned.

See Also
getOnValues()
getOnValueback to summary
private String getOnValue(int index)
getOnValueForWidgetback to summary
private String getOnValueForWidget(PDAnnotationWidget widget)
getOnValuesback to summary
public Set<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:Set<String>

the potential values setting the check box to the On state. If an empty Set is returned there is no appearance definition.

getValueback to summary
public 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:String

A non-null string.

getValueAsStringback to summary
public String getValueAsString()

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDField.getValueAsString.

Doc from org.apache.pdfbox.pdmodel.interactive.form.PDField.getValueAsString.

Returns a string representation of the "V" entry, or an empty string.

Returns:String

The list of widget annotations.

Annotations
@Override
isPushButtonback to summary
public boolean isPushButton()

Determines if push button bit is set.

Returns:boolean

true if type of button field is a push button.

isRadioButtonback to summary
public boolean isRadioButton()

Determines if radio button bit is set.

Returns:boolean

true if type of button field is a radio button.

setDefaultValueback to summary
public void setDefaultValue(String value)

Sets the default value.

Parameters
value:String

Name of option to select

Exceptions
IllegalArgumentException:
if the value is not a valid option.
setExportValuesback to summary
public void setExportValues(List<String> values)

This will set the export values.

Parameters
values:List<String>

List containing all possible export values. Supplying null or an empty list will remove the Opt entry.

See Also
getExportValues()
setValueback to summary
public void setValue(String value) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.interactive.form.PDField.setValue.

Set the selected option given its name, and try to update the visual appearance.

Parameters
value:String

Name of option to select

Annotations
@Override
Exceptions
IOException:
if the value could not be set
IllegalArgumentException:
if the value is not a valid option.
setValueback to summary
public void setValue(int index) throws IOException

Set 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:int

index of option to be selected

Exceptions
IOException:
if the value could not be set
IllegalArgumentException:
if the index provided is not a valid index.
updateByOptionback to summary
private void updateByOption(String value)
updateByValueback to summary
private void updateByValue(String value)