Package com.itextpdf.forms.fields
Class PdfChoiceFormField
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.forms.fields.AbstractPdfFormField
-
- com.itextpdf.forms.fields.PdfFormField
-
- com.itextpdf.forms.fields.PdfChoiceFormField
-
public class PdfChoiceFormField extends PdfFormField
An AcroForm field type representing any type of choice field. Choice fields are to be represented by a viewer as a list box or a combo box.
-
-
Field Summary
Fields Modifier and Type Field Description static int
FF_COMBO
If true, the field is a combo box.static int
FF_COMMIT_ON_SEL_CHANGE
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).static int
FF_DO_NOT_SPELL_CHECK
If true, text entered in the field shall be spell-checked.static int
FF_EDIT
If true, the combo box shall include an editable text box as well as a drop-down list.static int
FF_MULTI_SELECT
If true, more than one of the field's option items may be selected simultaneously.static int
FF_SORT
If true, the field's option items shall be sorted alphabetically.-
Fields inherited from class com.itextpdf.forms.fields.PdfFormField
checkType, FF_MULTILINE, FF_NO_EXPORT, FF_PASSWORD, FF_READ_ONLY, FF_REQUIRED, form, img, text
-
Fields inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
color, DEFAULT_FONT_SIZE, font, fontSize, MIN_FONT_SIZE, parent, pdfAConformanceLevel, pdfConformanceLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PdfChoiceFormField(PdfWidgetAnnotation widget, PdfDocument pdfDocument)
Creates a choice form field as a parent of aPdfWidgetAnnotation
.protected
PdfChoiceFormField(PdfDictionary pdfObject)
Creates a choice form field as a wrapper object around aPdfDictionary
.protected
PdfChoiceFormField(PdfDocument pdfDocument)
Creates a minimalPdfChoiceFormField
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfName
getFormType()
ReturnsCh
, the form type for choice form fields.PdfArray
getIndices()
Gets the currently selected items in the fieldPdfNumber
getTopIndex()
Gets the current index of the first option in a scrollable list.boolean
isCombo()
If true, the field is a combo box; if false, the field is a list box.boolean
isCommitOnSelChange()
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).boolean
isEdit()
If true, the combo box shall include an editable text box as well as a drop-down list; if false, it shall include only a drop-down list.boolean
isMultiSelect()
If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.boolean
isSort()
If true, the field's option items shall be sorted alphabetically.boolean
isSpellCheck()
If true, text entered in the field shall be spell-checked..private java.util.List<java.lang.String>
optionsToUnicodeNames()
PdfChoiceFormField
setCombo(boolean combo)
If true, the field is a combo box; if false, the field is a list box.PdfChoiceFormField
setCommitOnSelChange(boolean commitOnSelChange)
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).PdfChoiceFormField
setEdit(boolean edit)
If true, the combo box shall include an editable text box as well as a drop-down list; if false, it shall include only a drop-down list.PdfChoiceFormField
setIndices(PdfArray indices)
Sets the selected items in the field.PdfChoiceFormField
setListSelected(int[] optionNumbers)
Highlights the options.PdfChoiceFormField
setListSelected(java.lang.String[] optionValues)
Highlights the options.PdfChoiceFormField
setListSelected(java.lang.String[] optionValues, boolean generateAppearance)
Highlights the options and generates field appearance if needed.PdfChoiceFormField
setMultiSelect(boolean multiSelect)
If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.PdfChoiceFormField
setSort(boolean sort)
If true, the field's option items shall be sorted alphabetically.PdfChoiceFormField
setSpellCheck(boolean spellCheck)
If true, text entered in the field shall be spell-checked.PdfChoiceFormField
setTopIndex(int index)
Sets the index of the first visible option in a scrollable list.-
Methods inherited from class com.itextpdf.forms.fields.PdfFormField
addKid, addKid, addKid, getAdditionalAction, getAllChildFields, getAllChildFormFields, getAlternativeName, getAppearanceStates, getChildField, getChildFields, getChildFormAnnotations, getChildFormFields, getDefaultAppearance, getDefaultStyle, getDefaultValue, getDisplayValue, getFieldFlag, getFieldFlags, getFirstFormAnnotation, getFormFieldKeys, getFormType, getJustification, getKids, getMappingName, getOptions, getPartialFieldName, getRichText, getValue, getValueAsString, getWidgets, isFormField, isInReadingMode, isMultiline, isNoExport, isPassword, isReadOnly, isRequired, makeFieldFlag, makeFormField, makeFormFieldOrAnnotation, optionsArrayToString, regenerateField, release, removeChild, removeChildren, replaceKids, setAdditionalAction, setAlternativeName, setCheckType, setChildField, setColor, setDefaultStyle, setDefaultValue, setFieldFlag, setFieldFlag, setFieldFlags, setFieldName, setJustification, setMappingName, setNoExport, setOptions, setReadOnly, setRequired, setRichText, setValue, setValue, setValue, setValue, updateDefaultAppearance, updateFontAndFontSize
-
Methods inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
disableCurrentFieldRegeneration, disableFieldRegeneration, enableCurrentFieldRegeneration, enableFieldRegeneration, equals, getAcroFormObject, getColor, getDocument, getFieldName, getFont, getFontSize, getParent, getParentField, getPdfAConformanceLevel, getPdfConformanceLevel, getPdfObject, hashCode, isFieldRegenerationEnabled, isTerminalFormField, isWrappedObjectMustBeIndirect, put, remove, retrieveStyles, setColorNoRegenerate, setFont, setFontAndSize, setFontSize, setFontSize, setFontSizeAutoScale, setParent
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
FF_COMBO
public static final int FF_COMBO
If true, the field is a combo box. If false, the field is a list box.
-
FF_EDIT
public static final int FF_EDIT
If true, the combo box shall include an editable text box as well as a drop-down list. If false, it shall include only a drop-down list. This flag shall be used only if the Combo flag is true.
-
FF_SORT
public static final int FF_SORT
If true, the field's option items shall be sorted alphabetically. This flag is intended for use by writers, not by readers.
-
FF_MULTI_SELECT
public static final int FF_MULTI_SELECT
If true, more than one of the field's option items may be selected simultaneously. If false, at most one item shall be selected.
-
FF_DO_NOT_SPELL_CHECK
public static final int FF_DO_NOT_SPELL_CHECK
If true, text entered in the field shall be spell-checked.
-
FF_COMMIT_ON_SEL_CHANGE
public static final int FF_COMMIT_ON_SEL_CHANGE
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).
-
-
Constructor Detail
-
PdfChoiceFormField
protected PdfChoiceFormField(PdfDocument pdfDocument)
Creates a minimalPdfChoiceFormField
.- Parameters:
pdfDocument
- ThePdfDocument
instance.
-
PdfChoiceFormField
protected PdfChoiceFormField(PdfWidgetAnnotation widget, PdfDocument pdfDocument)
Creates a choice form field as a parent of aPdfWidgetAnnotation
.- Parameters:
widget
- The widget which will be a kid of thePdfChoiceFormField
.pdfDocument
- ThePdfDocument
instance.
-
PdfChoiceFormField
protected PdfChoiceFormField(PdfDictionary pdfObject)
Creates a choice form field as a wrapper object around aPdfDictionary
. ThisPdfDictionary
must be an indirect object.- Parameters:
pdfObject
- the dictionary to be wrapped, must have an indirect reference.
-
-
Method Detail
-
getFormType
public PdfName getFormType()
ReturnsCh
, the form type for choice form fields.- Overrides:
getFormType
in classPdfFormField
- Returns:
- the form type, as a
PdfName
-
setTopIndex
public PdfChoiceFormField setTopIndex(int index)
Sets the index of the first visible option in a scrollable list.- Parameters:
index
- the index of the first option- Returns:
- current
PdfChoiceFormField
-
getTopIndex
public PdfNumber getTopIndex()
Gets the current index of the first option in a scrollable list.- Returns:
- the index of the first option, as a
PdfNumber
-
setIndices
public PdfChoiceFormField setIndices(PdfArray indices)
Sets the selected items in the field.- Parameters:
indices
- a sorted array of indices representing selected items in the field- Returns:
- current
PdfChoiceFormField
-
setListSelected
public PdfChoiceFormField setListSelected(java.lang.String[] optionValues)
Highlights the options. If this method is used for Combo box, the first value in input array will be the field value.- Parameters:
optionValues
- Array of display values to be highlighted.- Returns:
- current
PdfChoiceFormField
.
-
setListSelected
public PdfChoiceFormField setListSelected(java.lang.String[] optionValues, boolean generateAppearance)
Highlights the options and generates field appearance if needed. If this method is used for Combo box, the first value in input array will be the field value- Parameters:
optionValues
- Array of options to be highlightedgenerateAppearance
- if false, appearance won't be regenerated- Returns:
- current
PdfChoiceFormField
-
setListSelected
public PdfChoiceFormField setListSelected(int[] optionNumbers)
Highlights the options. If this method is used for Combo box, the first value in input array will be the field value- Parameters:
optionNumbers
- The option numbers- Returns:
- The edited
PdfChoiceFormField
-
getIndices
public PdfArray getIndices()
Gets the currently selected items in the field- Returns:
- a sorted array of indices representing the currently selected items in the field
-
setCombo
public PdfChoiceFormField setCombo(boolean combo)
If true, the field is a combo box; if false, the field is a list box.- Parameters:
combo
- whether or not the field should be a combo box- Returns:
- current
PdfChoiceFormField
-
isCombo
public boolean isCombo()
If true, the field is a combo box; if false, the field is a list box.- Returns:
- whether or not the field is now a combo box.
-
setEdit
public PdfChoiceFormField setEdit(boolean edit)
If true, the combo box shall include an editable text box as well as a drop-down list; if false, it shall include only a drop-down list. This flag shall be used only if the Combo flag is true.- Parameters:
edit
- whether or not to add an editable text box- Returns:
- current
PdfChoiceFormField
-
isEdit
public boolean isEdit()
If true, the combo box shall include an editable text box as well as a drop-down list; if false, it shall include only a drop-down list. This flag shall be used only if the Combo flag is true.- Returns:
- whether or not there is currently an editable text box
-
setSort
public PdfChoiceFormField setSort(boolean sort)
If true, the field's option items shall be sorted alphabetically. This flag is intended for use by writers, not by readers.- Parameters:
sort
- whether or not to sort the items- Returns:
- current
PdfChoiceFormField
-
isSort
public boolean isSort()
If true, the field's option items shall be sorted alphabetically. This flag is intended for use by writers, not by readers.- Returns:
- whether or not the items are currently sorted
-
setMultiSelect
public PdfChoiceFormField setMultiSelect(boolean multiSelect)
If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.- Parameters:
multiSelect
- whether or not to allow multiple selection- Returns:
- current
PdfChoiceFormField
-
isMultiSelect
public boolean isMultiSelect()
If true, more than one of the field's option items may be selected simultaneously; if false, at most one item shall be selected.- Returns:
- whether or not multiple selection is currently allowed
-
setSpellCheck
public PdfChoiceFormField setSpellCheck(boolean spellCheck)
If true, text entered in the field shall be spell-checked.- Parameters:
spellCheck
- whether or not to require the PDF viewer to perform a spell check- Returns:
- current
PdfChoiceFormField
-
isSpellCheck
public boolean isSpellCheck()
If true, text entered in the field shall be spell-checked..- Returns:
- whether or not PDF viewer must perform a spell check
-
setCommitOnSelChange
public PdfChoiceFormField setCommitOnSelChange(boolean commitOnSelChange)
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).- Parameters:
commitOnSelChange
- whether or not to save changes immediately- Returns:
- current
PdfChoiceFormField
-
isCommitOnSelChange
public boolean isCommitOnSelChange()
If true, the new value shall be committed as soon as a selection is made (commonly with the pointing device).- Returns:
- whether or not to save changes immediately
-
optionsToUnicodeNames
private java.util.List<java.lang.String> optionsToUnicodeNames()
-
-