com.lowagie.text.pdf

Class 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
String[]choiceExports
Holds value of property choiceExports.
String[]choices
Holds value of property choices.
intchoiceSelection
Holds value of property choiceSelection.
StringdefaultText
Holds value of property defaultText.
BaseFontextensionFont
Holds value of property extensionFont.
floatextraMarginLeft
floatextraMarginTop
ArrayListsubstitutionFonts
Holds value of property substitutionFonts.
inttopFirst
Constructor Summary
TextField(PdfWriter writer, Rectangle box, String fieldName)
Creates a new TextField.
Method Summary
static voidchangeFontSize(Phrase p, float size)
static booleancheckRTL(String text)
PhrasecomposePhrase(String text, BaseFont ufont, Color color, float fontSize)
PdfAppearancegetAppearance()
String[]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.
PdfAppearancegetListAppearance()
PdfFormFieldgetListField()
Gets a new list field.
ArrayListgetSubstitutionFonts()
Gets the list of substitution fonts.
PdfFormFieldgetTextField()
Gets a new text field.
intgetTopFirst()
static StringremoveCRLF(String text)
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.
voidsetSubstitutionFonts(ArrayList substitutionFonts)
Sets a list of substitution fonts.

Field Detail

choiceExports

private String[] choiceExports
Holds value of property choiceExports.

choices

private String[] choices
Holds value of property choices.

choiceSelection

private int choiceSelection
Holds value of property choiceSelection.

defaultText

private String defaultText
Holds value of property defaultText.

extensionFont

private BaseFont extensionFont
Holds value of property extensionFont.

extraMarginLeft

private float extraMarginLeft

extraMarginTop

private float extraMarginTop

substitutionFonts

private ArrayList substitutionFonts
Holds value of property substitutionFonts.

topFirst

private int topFirst

Constructor Detail

TextField

public TextField(PdfWriter writer, Rectangle box, String fieldName)
Creates a new TextField.

Parameters: writer the document PdfWriter box the field location and dimensions fieldName the field name. If null only the widget keys will be included in the field allowing it to be used as a kid field.

Method Detail

changeFontSize

private static void changeFontSize(Phrase p, float size)

checkRTL

private static boolean checkRTL(String text)

composePhrase

private Phrase composePhrase(String text, BaseFont ufont, Color color, float fontSize)

getAppearance

public PdfAppearance getAppearance()

getChoiceExports

public String[] getChoiceExports()
Gets the export values in list/combo fields.

Returns: the export values in list/combo fields

getChoiceField

protected PdfFormField getChoiceField(boolean isList)

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

getChoiceSelection

public int getChoiceSelection()
Gets the zero based index of the selected item.

Returns: the zero based index of the selected item

getComboField

public PdfFormField getComboField()
Gets a new combo field.

Returns: a new combo field

Throws: IOException on error DocumentException on error

getDefaultText

public String getDefaultText()
Gets the default text.

Returns: the default text

getExtensionFont

public BaseFont getExtensionFont()
Gets the extensionFont. This font will be searched before the substitution fonts. It may be null.

Returns: the extensionFont

getListAppearance

PdfAppearance getListAppearance()

getListField

public PdfFormField getListField()
Gets a new list field.

Returns: a new list field

Throws: IOException on error DocumentException on error

getSubstitutionFonts

public ArrayList getSubstitutionFonts()
Gets the list of substitution fonts. The list is composed of BaseFont and can be null. The fonts in this list will be used if the original font doesn't contain the needed glyphs.

Returns: the list

getTextField

public PdfFormField getTextField()
Gets a new text field.

Returns: a new text field

Throws: IOException on error DocumentException on error

getTopFirst

int getTopFirst()

removeCRLF

private static String removeCRLF(String text)

setChoiceExports

public void setChoiceExports(String[] choiceExports)
Sets the export values in list/combo fields. If this array is null then the choice values will also be used as the export values.

Parameters: choiceExports the export values in list/combo fields

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

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

setDefaultText

public void setDefaultText(String defaultText)
Sets the default text. It is only meaningful for text fields.

Parameters: defaultText the default text

setExtensionFont

public void setExtensionFont(BaseFont extensionFont)
Sets the extensionFont. This font will be searched before the substitution fonts. It may be null.

Parameters: extensionFont New value of property extensionFont.

setExtraMargin

public void setExtraMargin(float extraMarginLeft, float extraMarginTop)
Sets extra margins in text fields to better mimic the Acrobat layout.

Parameters: extraMarginLeft the extra marging left extraMarginTop the extra margin top

setSubstitutionFonts

public void setSubstitutionFonts(ArrayList substitutionFonts)
Sets a list of substitution fonts. The list is composed of BaseFont and can also be null. The fonts in this list will be used if the original font doesn't contain the needed glyphs.

Parameters: substitutionFonts the list