Package com.lowagie.text.pdf
Class TextField
- java.lang.Object
-
- com.lowagie.text.pdf.BaseField
-
- com.lowagie.text.pdf.TextField
-
public class TextField extends BaseField
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.- Author:
- Paulo Soares (psoares@consiste.pt)
-
-
Field Summary
-
Fields inherited from class com.lowagie.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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChoiceSelection(int selection)adds another (or a first I suppose) selection to a MULTISELECT list.PdfAppearancegetAppearance()Get thePdfAppearanceof a text or combo fieldString[]getChoiceExports()Gets the export values in list/combo fields.protected PdfFormFieldgetChoiceField(boolean isList)String[]getChoices()Gets the choices to be presented to the user in list/combo fields.intgetChoiceSelection()Gets the zero based index of the selected item.PdfFormFieldgetComboField()Gets a new combo field.StringgetDefaultText()Gets the default text.BaseFontgetExtensionFont()Gets the extensionFont.PdfFormFieldgetListField()Gets a new list field.List<BaseFont>getSubstitutionFontList()Gets the list of substitution fonts.ArrayListgetSubstitutionFonts()Deprecated.PdfFormFieldgetTextField()Gets a new text field.ArrayList<Integer>gteChoiceSelections()static StringobfuscatePassword(String text)Obfuscates a passwordString.static StringremoveCRLF(String text)Removes CRLF from aString.voidsetChoiceExports(String[] choiceExports)Sets the export values in list/combo fields.voidsetChoices(String[] choices)Sets the choices to be presented to the user in list/combo fields.voidsetChoiceSelection(int choiceSelection)Sets the zero based index of the selected item.voidsetChoiceSelections(ArrayList selections)Deprecated.voidsetChoiceSelections(List<Integer> selections)replaces the existing selections with the param.voidsetDefaultText(String defaultText)Sets the default text.voidsetExtensionFont(BaseFont extensionFont)Sets the extensionFont.voidsetExtraMargin(float extraMarginLeft, float extraMarginTop)Sets extra margins in text fields to better mimic the Acrobat layout.voidsetSubstitutionFontList(List<BaseFont> substitutionFonts)Sets a list of substitution fonts.voidsetSubstitutionFonts(List<BaseFont> substitutionFonts)Deprecated.-
Methods inherited from class com.lowagie.text.pdf.BaseField
breakLines, breakLines, getAlignment, getAllHardBreaks, 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
-
-
-
-
Constructor Detail
-
TextField
public TextField(PdfWriter writer, Rectangle box, String fieldName)
Creates a newTextField.- Parameters:
writer- the documentPdfWriterbox- the field location and dimensionsfieldName- the field name. Ifnullonly the widget keys will be included in the field allowing it to be used as a kid field.
-
-
Method Detail
-
removeCRLF
public static String removeCRLF(String text)
Removes CRLF from aString.- Parameters:
text- the String to remove the CRLF from- Returns:
- String
- Since:
- 2.1.5
-
obfuscatePassword
public static String obfuscatePassword(String text)
Obfuscates a passwordString. Every character is replaced by an asterisk (*).- Parameters:
text- the text to obfuscate- Returns:
- String
- Since:
- 2.1.5
-
getAppearance
public PdfAppearance getAppearance() throws IOException, DocumentException
Get thePdfAppearanceof a text or combo field- Returns:
- A
PdfAppearance - Throws:
IOException- on errorDocumentException- on error
-
getTextField
public PdfFormField getTextField() throws IOException, DocumentException
Gets a new text field.- Returns:
- a new text field
- Throws:
IOException- on errorDocumentException- on error
-
getComboField
public PdfFormField getComboField() throws IOException, DocumentException
Gets a new combo field.- Returns:
- a new combo field
- Throws:
IOException- on errorDocumentException- on error
-
getListField
public PdfFormField getListField() throws IOException, DocumentException
Gets a new list field.- Returns:
- a new list field
- Throws:
IOException- on errorDocumentException- on error
-
getChoiceField
protected PdfFormField getChoiceField(boolean isList) throws IOException, DocumentException
- Throws:
IOExceptionDocumentException
-
getDefaultText
public String getDefaultText()
Gets the default text.- Returns:
- the default text
-
setDefaultText
public void setDefaultText(String defaultText)
Sets the default text. It is only meaningful for text fields.- Parameters:
defaultText- the default text
-
getChoices
public String[] getChoices()
Gets the choices to be presented to the user in list/combo fields.- Returns:
- the choices to be presented to the user
-
setChoices
public void setChoices(String[] choices)
Sets the choices to be presented to the user in list/combo fields.- Parameters:
choices- the choices to be presented to the user
-
getChoiceExports
public String[] getChoiceExports()
Gets the export values in list/combo fields.- Returns:
- the export values in list/combo fields
-
setChoiceExports
public void setChoiceExports(String[] choiceExports)
Sets the export values in list/combo fields. If this array isnullthen 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
-
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 unlessthis.options & MUTLISELECT != 0- Parameters:
selection- new selection
-
setChoiceSelections
@Deprecated public void setChoiceSelections(ArrayList selections)
Deprecated.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.
-
setChoiceSelections
public void setChoiceSelections(List<Integer> selections)
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.
-
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
@Deprecated public ArrayList getSubstitutionFonts()
Deprecated.Gets the list of substitution fonts. The list is composed ofBaseFontand can benull. The fonts in this list will be used if the original font doesn't contain the needed glyphs.- Returns:
- the list
-
getSubstitutionFontList
public List<BaseFont> getSubstitutionFontList()
Gets the list of substitution fonts. The list is composed ofBaseFontand can benull. The fonts in this list will be used if the original font doesn't contain the needed glyphs.- Returns:
- the list
-
setSubstitutionFonts
@Deprecated public void setSubstitutionFonts(List<BaseFont> substitutionFonts)
Deprecated.Sets a list of substitution fonts. The list is composed ofBaseFontand 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
-
setSubstitutionFontList
public void setSubstitutionFontList(List<BaseFont> substitutionFonts)
Sets a list of substitution fonts. The list is composed ofBaseFontand 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
public BaseFont getExtensionFont()
Gets the extensionFont. This font will be searched before the substitution fonts. It may benull.- Returns:
- the extensionFont
-
setExtensionFont
public void setExtensionFont(BaseFont extensionFont)
Sets the extensionFont. This font will be searched before the substitution fonts. It may benull.- Parameters:
extensionFont- New value of property extensionFont.
-
-