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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]
choiceExports
Holds value of property choiceExports.private java.lang.String[]
choices
Holds value of property choices.private java.util.ArrayList<java.lang.Integer>
choiceSelections
Holds value of property choiceSelection.private java.lang.String
defaultText
Holds value of property defaultText.private BaseFont
extensionFont
Holds value of property extensionFont.private float
extraMarginLeft
private float
extraMarginTop
private java.util.List<BaseFont>
substitutionFonts
Holds value of property substitutionFonts.private int
topFirst
-
Fields inherited from class com.lowagie.text.pdf.BaseField
alignment, alternateFieldName, 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, INVISIBLE, LOCKED, mappingName, maxCharacterLength, MULTILINE, MULTISELECT, NOVIEW, options, PASSWORD, PRINT, READ_ONLY, REQUIRED, rotation, text, textColor, visibility, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT, writer
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
checkRTL(java.lang.String text)
private Phrase
composePhrase(java.lang.String text, BaseFont ufont, java.awt.Color color, float fontSize)
PdfAppearance
getAppearance()
Get thePdfAppearance
of a text or combo fieldjava.lang.String[]
getChoiceExports()
Gets the export values in list/combo fields.protected PdfFormField
getChoiceField(boolean isList)
java.lang.String[]
getChoices()
Gets the choices to be presented to the user in list/combo fields.int
getChoiceSelection()
Gets the zero based index of the selected item.PdfFormField
getComboField()
Gets a new combo field.java.lang.String
getDefaultText()
Gets the default text.BaseFont
getExtensionFont()
Gets the extensionFont.(package private) PdfAppearance
getListAppearance()
Get thePdfAppearance
of a list fieldPdfFormField
getListField()
Gets a new list field.java.util.List<BaseFont>
getSubstitutionFontList()
Gets the list of substitution fonts.private int
getTextAlignment(int runDirection)
Flip text alignment for RTL texts Not sure why but this is neededPdfFormField
getTextField()
Gets a new text field.private int
getTopChoice()
(package private) int
getTopFirst()
java.util.ArrayList<java.lang.Integer>
gteChoiceSelections()
static java.lang.String
obfuscatePassword(java.lang.String text)
Obfuscates a passwordString
.static java.lang.String
removeCRLF(java.lang.String text)
Removes CRLF from aString
.void
setChoiceExports(java.lang.String[] choiceExports)
Sets the export values in list/combo fields.void
setChoices(java.lang.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(java.util.List<java.lang.Integer> selections)
replaces the existing selections with the param.void
setDefaultText(java.lang.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
setSubstitutionFontList(java.util.List<BaseFont> substitutionFonts)
Sets a list of substitution fonts.private static int
textRunDirection(java.lang.String ptext)
private static int
textRunDirectionByContent(java.lang.String ptext)
Chose the run direction of a text field by it's contentprivate static int
textRunDirectionDefault(java.lang.String ptext)
private void
writeMultipleValues(PdfFormField field, java.lang.String[][] mix)
-
Methods inherited from class com.lowagie.text.pdf.BaseField
breakLines, getAlignment, getAllHardBreaks, getAlternateFieldName, getBackgroundColor, getBorderAppearance, getBorderColor, getBorderStyle, getBorderWidth, getBox, getFieldName, getFont, getFontSize, getMappingName, getMaxCharacterLength, getOptions, getRealFont, getRotation, getText, getTextColor, getVisibility, getWriter, moveFields, setAlignment, setAlternateFieldName, setBackgroundColor, setBorderColor, setBorderStyle, setBorderWidth, setBox, setFieldName, setFont, setFontSize, setMappingName, setMaxCharacterLength, setOptions, setRotation, setRotationFromPage, setText, setTextColor, setVisibility, setWriter, trimRight
-
-
-
-
Field Detail
-
defaultText
private java.lang.String defaultText
Holds value of property defaultText.
-
choices
private java.lang.String[] choices
Holds value of property choices.
-
choiceExports
private java.lang.String[] choiceExports
Holds value of property choiceExports.
-
choiceSelections
private java.util.ArrayList<java.lang.Integer> choiceSelections
Holds value of property choiceSelection.
-
topFirst
private int topFirst
-
extraMarginLeft
private float extraMarginLeft
-
extraMarginTop
private float extraMarginTop
-
substitutionFonts
private java.util.List<BaseFont> substitutionFonts
Holds value of property substitutionFonts.
-
extensionFont
private BaseFont extensionFont
Holds value of property extensionFont.
-
-
Constructor Detail
-
TextField
public TextField(PdfWriter writer, Rectangle box, java.lang.String fieldName)
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 Detail
-
checkRTL
private static boolean checkRTL(java.lang.String text)
-
textRunDirectionDefault
private static int textRunDirectionDefault(java.lang.String ptext)
-
textRunDirectionByContent
private static int textRunDirectionByContent(java.lang.String ptext)
Chose the run direction of a text field by it's content- Parameters:
ptext
- text field content- Returns:
- int run direction (PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL or PdfWriter.RUN_DIRECTION_NO_BIDI)
-
textRunDirection
private static int textRunDirection(java.lang.String ptext)
-
changeFontSize
private static void changeFontSize(Phrase p, float size)
-
removeCRLF
public static java.lang.String removeCRLF(java.lang.String text)
Removes CRLF from aString
.- Parameters:
text
- the String to remove the CRLF from- Returns:
- String
- Since:
- 2.1.5
-
obfuscatePassword
public static java.lang.String obfuscatePassword(java.lang.String text)
Obfuscates a passwordString
. Every character is replaced by an asterisk (*).- Parameters:
text
- the text to obfuscate- Returns:
- String
- Since:
- 2.1.5
-
composePhrase
private Phrase composePhrase(java.lang.String text, BaseFont ufont, java.awt.Color color, float fontSize)
-
getTextAlignment
private int getTextAlignment(int runDirection)
Flip text alignment for RTL texts Not sure why but this is needed
-
getAppearance
public PdfAppearance getAppearance() throws java.io.IOException, DocumentException
Get thePdfAppearance
of a text or combo field- Returns:
- A
PdfAppearance
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getListAppearance
PdfAppearance getListAppearance() throws java.io.IOException, DocumentException
Get thePdfAppearance
of a list field- Returns:
- A
PdfAppearance
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getTextField
public PdfFormField getTextField() throws java.io.IOException, DocumentException
Gets a new text field.- Returns:
- a new text field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getComboField
public PdfFormField getComboField() throws java.io.IOException, DocumentException
Gets a new combo field.- Returns:
- a new combo field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getListField
public PdfFormField getListField() throws java.io.IOException, DocumentException
Gets a new list field.- Returns:
- a new list field
- Throws:
java.io.IOException
- on errorDocumentException
- on error
-
getTopChoice
private int getTopChoice()
-
getChoiceField
protected PdfFormField getChoiceField(boolean isList) throws java.io.IOException, DocumentException
- Throws:
java.io.IOException
DocumentException
-
writeMultipleValues
private void writeMultipleValues(PdfFormField field, java.lang.String[][] mix)
-
getDefaultText
public java.lang.String getDefaultText()
Gets the default text.- Returns:
- the default text
-
setDefaultText
public void setDefaultText(java.lang.String defaultText)
Sets the default text. It is only meaningful for text fields.- Parameters:
defaultText
- the default text
-
getChoices
public java.lang.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(java.lang.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 java.lang.String[] getChoiceExports()
Gets the export values in list/combo fields.- Returns:
- the export values in list/combo fields
-
setChoiceExports
public void setChoiceExports(java.lang.String[] choiceExports)
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
-
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
-
gteChoiceSelections
public java.util.ArrayList<java.lang.Integer> gteChoiceSelections()
-
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
public void setChoiceSelections(java.util.List<java.lang.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.
-
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
-
getSubstitutionFontList
public java.util.List<BaseFont> getSubstitutionFontList()
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
-
setSubstitutionFontList
public void setSubstitutionFontList(java.util.List<BaseFont> substitutionFonts)
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
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.
-
-