class HexaPDF::Type::AcroForm::ChoiceField

Parent

AcroForm choice fields contain multiple text items of which one (or, if so flagged, more) may be selected.

They are divided into scrollable list boxes and combo boxes. To create a list or combo box, use the appropriate convenience methods on the main Form instance (HexaPDF::Document#acro_form). By using those methods, everything needed is automatically set up.

Type Specific Field Flags

See the class description for Field for the general field flags.

:combo

If set, the field represents a combo box.

:edit

If set, the combo box includes an editable text box for entering arbitrary values. Therefore the ‘combo’ flag also needs to be set.

:sort

The option items have to be sorted alphabetically. This flag is intended for PDF writers, not readers which should display the items in the order they appear.

:multi_select

If set, more than one item may be selected.

:do_not_spell_check

The text should not be spell-checked.

:commit_on_sel_change

If set, a new value should be commited as soon as a selection is made.

See: PDF2.0 s12.7.5.4

Constants

FLAGS_BIT_MAPPING

Updated list of field flags.

Public Instance Methods

combo_box?()

Returns true if this choice field represents a combo box.

concrete_field_type()

Returns the concrete choice field type, either :list_box, :combo_box or :editable_combo_box.

create_appearances(force: false)

Creates appropriate appearances for all widgets if they don’t already exist.

For information on how this is done see AppearanceGenerator.

Note that no new appearances are created if the dictionary fields involved in the creation of the appearance stream have not been changed between invocations.

By setting force to true the creation of the appearances can be forced.

default_field_value()

Returns the default field value.

See: field_value

default_field_value=(value)

Sets the default field value.

See: field_value=

export_values()

Returns the export values of the option items.

If you need the display strings (as in most cases), use the option_items method.

field_value()

Returns the field value which represents the currently selected item(s).

If no item is selected, nil is returned. If multiple values are selected, the return value is an array of strings, otherwise it is just a string.

field_value=(value)

Sets the field value to the given string or array of strings.

The dictionary field /I is also modified to correctly represent the selected item(s).

initialize_as_combo_box()

Initializes the button field to be a combo box.

This method should only be called directly after creating a new choice field because it doesn’t completely reset the object.

initialize_as_list_box()

Initializes the choice field to be a list box.

This method should only be called directly after creating a new choice field because it doesn’t completely reset the object.

list_box?()

Returns true if this choice field represents a list box.

list_box_top_index()

Returns the index of the first visible option item of a list box.

list_box_top_index=(index)

Makes the option item referred to via the given index the first visible option item of a list box.

option_items()

Returns the array with the available option items.

Note that this only returns the option items themselves! For getting the export values, the export_values method has to be used.

option_items=(value)

Sets the array with the available option items to the given value.

Each entry in the array may either be a string representing the text to be displayed. Or an array of two strings where the first describes the export value (to be used when exporting form field data from the document) and the second is the display value.

See: option_items, export_values

update_widgets()

Updates the widgets so that they reflect the current field value.