Class TextField
java.lang.Object
com.aowagie.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.
- Author:
- Paulo Soares (psoares@consiste.pt)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected Colorprotected Colorprotected intprotected floatprotected Rectanglestatic final intcombo box flag.static final intIf set the combo box includes an editable text box as well as a drop list; if clear, it includes only a drop list.protected StringHolds value of property fieldName.protected floatstatic final intThe field is hidden.protected intHolds value of property maxCharacterLength.protected intHolds value of property options.protected intHolds value of property rotation.protected Stringprotected Colorprotected intHolds value of property visibility.protected PdfWriter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the text horizontal alignment.com.aowagie.text.pdf.PdfAppearanceGet thePdfAppearanceof a text or combo fieldGets the background color.protected com.aowagie.text.pdf.PdfAppearanceGets the border color.intGets the border style.floatGets the border width in points.getBox()Gets the field dimension and position.String[]Gets the export values in list/combo fields.protected PdfFormFieldgetChoiceField(boolean isList) String[]Gets the choices to be presented to the user in list/combo fields.intGets the zero based index of the selected item.Gets a new combo field.Gets the default text.Gets the extensionFont.Gets the field name.getFont()Gets the text font.floatGets the font size.Gets a new list field.intGets the maximum length of the field's text, in characters.intGets the option flags.protected BaseFontintGets the field rotation.Gets the list of substitution fonts.getText()Gets the text.Gets the text color.Gets a new text field.intGets the field visibility flag.Getter for property writer.static StringobfuscatePassword(String text) Obfuscates a passwordString.static StringremoveCRLF(String text) Removes CRLF from aString.voidsetAlignment(int alignment) Sets the text horizontal alignment.voidsetBackgroundColor(Color backgroundColor) Sets the background color.voidsetBorderColor(Color borderColor) Sets the border color.voidsetBorderStyle(int borderStyle) Sets the border style.voidsetBorderWidth(float borderWidth) Sets the border width in points.voidSets the field dimension and position.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.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.voidsetFieldName(String fieldName) Sets the field name.voidSets the text font.voidsetFontSize(float fontSize) Sets the font size.voidsetMaxCharacterLength(int maxCharacterLength) Sets the maximum length of the field's text, in characters.voidsetOptions(int options) Sets the option flags.voidsetRotation(int rotation) Sets the field rotation.voidsetRotationFromPage(Rectangle page) Convenience method to set the field rotation the same as the page rotation.voidsetSubstitutionFonts(ArrayList substitutionFonts) Sets a list of substitution fonts.voidSets the text for text fields.voidsetTextColor(Color textColor) Sets the text color.voidsetVisibility(int visibility) Sets the field visibility flag.voidSetter for property writer.
-
Field Details
-
HIDDEN
public static final int HIDDENThe field is hidden.- See Also:
-
EDIT
public static final int EDITIf set the combo box includes an editable text box as well as a drop list; if clear, it includes only a drop list. This flag is only meaningful with combo fields.- See Also:
-
COMB
public static final int COMBcombo box flag.- See Also:
-
borderWidth
protected float borderWidth -
borderStyle
protected int borderStyle -
borderColor
-
backgroundColor
-
textColor
-
fontSize
protected float fontSize -
alignment
protected int alignment -
writer
-
text
-
box
-
rotation
protected int rotationHolds value of property rotation. -
visibility
protected int visibilityHolds value of property visibility. -
fieldName
Holds value of property fieldName. -
options
protected int optionsHolds value of property options. -
maxCharacterLength
protected int maxCharacterLengthHolds value of property maxCharacterLength.
-
-
Constructor Details
-
TextField
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 Details
-
removeCRLF
-
obfuscatePassword
-
getAppearance
Get thePdfAppearanceof a text or combo 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
-
getChoiceField
- Throws:
IOExceptionDocumentException
-
getDefaultText
-
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 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
-
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 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
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
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.
-
getRealFont
- Throws:
IOExceptionDocumentException
-
getBorderAppearance
protected com.aowagie.text.pdf.PdfAppearance getBorderAppearance() -
getBorderWidth
public float getBorderWidth()Gets the border width in points.- Returns:
- the border width in points
-
setBorderWidth
public void setBorderWidth(float borderWidth) Sets the border width in points. To eliminate the border set the border color tonull.- Parameters:
borderWidth- the border width in points
-
getBorderStyle
public int getBorderStyle()Gets the border style.- Returns:
- the border style
-
setBorderStyle
public void setBorderStyle(int borderStyle) Sets the border style. The styles are found inPdfBorderDictionaryand can beSTYLE_SOLID,STYLE_DASHED,STYLE_BEVELED,STYLE_INSETandSTYLE_UNDERLINE.- Parameters:
borderStyle- the border style
-
getBorderColor
-
setBorderColor
Sets the border color. Set tonullto remove the border.- Parameters:
borderColor- the border color
-
getBackgroundColor
-
setBackgroundColor
Sets the background color. Set tonullfor transparent background.- Parameters:
backgroundColor- the background color
-
getTextColor
-
setTextColor
Sets the text color. Ifnullthe color used will be black.- Parameters:
textColor- the text color
-
getFont
-
setFont
Sets the text font. Ifnullthen Helvetica will be used.- Parameters:
font- the text font
-
getFontSize
public float getFontSize()Gets the font size.- Returns:
- the font size
-
setFontSize
public void setFontSize(float fontSize) Sets the font size. If 0 then auto-sizing will be used but only for text fields.- Parameters:
fontSize- the font size
-
getAlignment
public int getAlignment()Gets the text horizontal alignment.- Returns:
- the text horizontal alignment
-
setAlignment
public void setAlignment(int alignment) Sets the text horizontal alignment. It can beElement.ALIGN_LEFT,Element.ALIGN_CENTERandElement.ALIGN_RIGHT.- Parameters:
alignment- the text horizontal alignment
-
getText
-
setText
-
getBox
Gets the field dimension and position.- Returns:
- the field dimension and position
-
setBox
Sets the field dimension and position.- Parameters:
box- the field dimension and position
-
getRotation
public int getRotation()Gets the field rotation.- Returns:
- the field rotation
-
setRotation
public void setRotation(int rotation) Sets the field rotation. This value should be the same as the page rotation where the field will be shown.- Parameters:
rotation- the field rotation
-
setRotationFromPage
Convenience method to set the field rotation the same as the page rotation.- Parameters:
page- the page
-
getVisibility
public int getVisibility()Gets the field visibility flag.- Returns:
- the field visibility flag
-
setVisibility
public void setVisibility(int visibility) Sets the field visibility flag. This flags can be one ofVISIBLE,HIDDEN,VISIBLE_BUT_DOES_NOT_PRINTandHIDDEN_BUT_PRINTABLE.- Parameters:
visibility- field visibility flag
-
getFieldName
-
setFieldName
Sets the field name.- Parameters:
fieldName- the field name. Ifnullonly the widget keys will be included in the field allowing it to be used as a kid field.
-
getOptions
public int getOptions()Gets the option flags.- Returns:
- the option flags
-
setOptions
public void setOptions(int options) Sets the option flags. The option flags can be a combination by oring ofREAD_ONLY,REQUIRED,MULTILINE,DO_NOT_SCROLL,PASSWORD,FILE_SELECTION,DO_NOT_SPELL_CHECKandEDIT.- Parameters:
options- the option flags
-
getMaxCharacterLength
public int getMaxCharacterLength()Gets the maximum length of the field's text, in characters.- Returns:
- the maximum length of the field's text, in characters.
-
setMaxCharacterLength
public void setMaxCharacterLength(int maxCharacterLength) Sets the maximum length of the field's text, in characters. It is only meaningful for text fields.- Parameters:
maxCharacterLength- the maximum length of the field's text, in characters
-
getWriter
-
setWriter
Setter for property writer.- Parameters:
writer- New value of property writer.
-