Package com.itextpdf.text.pdf
Class TextField
java.lang.Object
com.itextpdf.text.pdf.BaseField
com.itextpdf.text.pdf.TextField
Supports text, combo and list fields generating the correct appearances.
All the option in the Acrobat GUI are supported in an easy to use API.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String[]
Holds value of property choiceExports.private String[]
Holds value of property choices.Holds value of property choiceSelection.private String
Holds value of property defaultText.private BaseFont
Holds value of property extensionFont.private float
private float
Holds value of property substitutionFonts.private int
private int
Represents the /TI valueFields inherited from class com.itextpdf.text.pdf.BaseField
alignment, backgroundColor, BORDER_WIDTH_MEDIUM, BORDER_WIDTH_THICK, BORDER_WIDTH_THIN, borderColor, borderStyle, borderWidth, box, COMB, DO_NOT_SCROLL, DO_NOT_SPELL_CHECK, EDIT, fieldName, FILE_SELECTION, font, fontSize, HIDDEN, HIDDEN_BUT_PRINTABLE, maxCharacterLength, MULTILINE, MULTISELECT, options, PASSWORD, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChoiceSelection
(int selection) Adds another (or a first I suppose) selection to a MULTISELECT list.private static void
changeFontSize
(Phrase p, float size) private static boolean
private Phrase
composePhrase
(String text, BaseFont ufont, BaseColor color, float fontSize) Get thePdfAppearance
of a text or combo fieldString[]
Gets the export values in list/combo fields.protected PdfFormField
getChoiceField
(boolean isList) String[]
Gets the choices to be presented to the user in list/combo fields.int
Gets the zero based index of the selected item.Gets the selected items.Gets a new combo field.Gets the default text.Gets the extensionFont.(package private) PdfAppearance
Get thePdfAppearance
of a list fieldGets a new list field.Gets the list of substitution fonts.Gets a new text field.private int
(package private) int
int
Returns the index of the top visible choice of a list.static String
obfuscatePassword
(String text) Obfuscates a passwordString
.static String
removeCRLF
(String text) Removes CRLF from aString
.void
setChoiceExports
(String[] choiceExports) Sets the export values in list/combo fields.void
setChoices
(String[] choices) Sets the choices to be presented to the user in list/combo fields.void
setChoiceSelection
(int choiceSelection) Sets the zero based index of the selected item.void
setChoiceSelections
(ArrayList<Integer> selections) Replaces the existing selections with the param.void
setDefaultText
(String defaultText) Sets the default text.void
setExtensionFont
(BaseFont extensionFont) Sets the extensionFont.void
setExtraMargin
(float extraMarginLeft, float extraMarginTop) Sets extra margins in text fields to better mimic the Acrobat layout.void
setSubstitutionFonts
(ArrayList<BaseFont> substitutionFonts) Sets a list of substitution fonts.void
setVisibleTopChoice
(int visibleTopChoice) Sets the top visible choice for lists;private void
writeMultipleValues
(PdfFormField field, String[][] mix) Methods inherited from class com.itextpdf.text.pdf.BaseField
breakLines, getAlignment, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getHardBreaks, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRight
-
Field Details
-
defaultText
Holds value of property defaultText. -
choices
Holds value of property choices. -
choiceExports
Holds value of property choiceExports. -
choiceSelections
Holds value of property choiceSelection. -
topFirst
private int topFirst -
visibleTopChoice
private int visibleTopChoiceRepresents the /TI value -
extraMarginLeft
private float extraMarginLeft -
extraMarginTop
private float extraMarginTop -
substitutionFonts
Holds value of property substitutionFonts. -
extensionFont
Holds value of property extensionFont.
-
-
Constructor Details
-
TextField
Creates a newTextField
.- Parameters:
writer
- the documentPdfWriter
box
- the field location and dimensionsfieldName
- the field name. Ifnull
only the widget keys will be included in the field allowing it to be used as a kid field.
-
-
Method Details
-
checkRTL
-
changeFontSize
-
composePhrase
-
removeCRLF
Removes CRLF from aString
.- Parameters:
text
-- Returns:
- String
- Since:
- 2.1.5
-
obfuscatePassword
Obfuscates a passwordString
. Every character is replaced by an asterisk (*).- Parameters:
text
-- Returns:
- String
- Since:
- 2.1.5
-
getAppearance
Get thePdfAppearance
of a text or combo field- Returns:
- A
PdfAppearance
- Throws:
IOException
- on errorDocumentException
- on error
-
getListAppearance
Get thePdfAppearance
of a list field- Returns:
- A
PdfAppearance
- Throws:
IOException
- on errorDocumentException
- on error
-
getTextField
Gets a new text field.- Returns:
- a new text field
- Throws:
IOException
- on errorDocumentException
- on error
-
getComboField
Gets a new combo field.- Returns:
- a new combo field
- Throws:
IOException
- on errorDocumentException
- on error
-
getListField
Gets a new list field.- Returns:
- a new list field
- Throws:
IOException
- on errorDocumentException
- on error
-
getTopChoice
private int getTopChoice() -
getChoiceField
- Throws:
IOException
DocumentException
-
writeMultipleValues
-
getDefaultText
Gets the default text.- Returns:
- the default text
-
setDefaultText
Sets the default text. It is only meaningful for text fields.- Parameters:
defaultText
- the default text
-
getChoices
Gets the choices to be presented to the user in list/combo fields.- Returns:
- the choices to be presented to the user
-
setChoices
Sets the choices to be presented to the user in list/combo fields.- Parameters:
choices
- the choices to be presented to the user
-
getChoiceExports
Gets the export values in list/combo fields.- Returns:
- the export values in list/combo fields
-
setChoiceExports
Sets the export values in list/combo fields. If this array isnull
then the choice values will also be used as the export values.- Parameters:
choiceExports
- the export values in list/combo fields
-
getChoiceSelection
public int getChoiceSelection()Gets the zero based index of the selected item.- Returns:
- the zero based index of the selected item
-
getChoiceSelections
Gets the selected items.- Returns:
- the selected items
- Since:
- 5.0.1
-
setVisibleTopChoice
public void setVisibleTopChoice(int visibleTopChoice) Sets the top visible choice for lists;- Parameters:
visibleTopChoice
- index of the first visible item (zero-based array)- Since:
- 5.5.3
-
getVisibleTopChoice
public int getVisibleTopChoice()Returns the index of the top visible choice of a list. Default is -1.- Returns:
- the index of the top visible choice
-
setChoiceSelection
public void setChoiceSelection(int choiceSelection) Sets the zero based index of the selected item.- Parameters:
choiceSelection
- the zero based index of the selected item
-
addChoiceSelection
public void addChoiceSelection(int selection) Adds another (or a first I suppose) selection to a MULTISELECT list. This doesn't do anything unless this.options & MUTLISELECT != 0- Parameters:
selection
- new selection
-
setChoiceSelections
Replaces the existing selections with the param. If this field isn't a MULTISELECT list, all but the first element will be removed.- Parameters:
selections
- new selections. If null, it clear()s the underlying ArrayList.
-
getTopFirst
int getTopFirst() -
setExtraMargin
public void setExtraMargin(float extraMarginLeft, float extraMarginTop) Sets extra margins in text fields to better mimic the Acrobat layout.- Parameters:
extraMarginLeft
- the extra margin leftextraMarginTop
- the extra margin top
-
getSubstitutionFonts
Gets the list of substitution fonts. The list is composed ofBaseFont
and can benull
. The fonts in this list will be used if the original font doesn't contain the needed glyphs.- Returns:
- the list
-
setSubstitutionFonts
Sets a list of substitution fonts. The list is composed ofBaseFont
and can also benull
. The fonts in this list will be used if the original font doesn't contain the needed glyphs.- Parameters:
substitutionFonts
- the list
-
getExtensionFont
Gets the extensionFont. This font will be searched before the substitution fonts. It may benull
.- Returns:
- the extensionFont
-
setExtensionFont
Sets the extensionFont. This font will be searched before the substitution fonts. It may benull
.- Parameters:
extensionFont
- New value of property extensionFont.
-