Class TextField
java.lang.Object
org.openpdf.text.pdf.BaseField
org.openpdf.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 StringHolds value of property defaultText.private BaseFontHolds value of property extensionFont.private floatprivate floatHolds value of property substitutionFonts.private intFields inherited from class 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChoiceSelection(int selection) adds another (or a first I suppose) selection to a MULTISELECT list.private static voidchangeFontSize(Phrase p, float size) private static booleanprivate PhrasecomposePhrase(String text, BaseFont ufont, Color color, float fontSize) Get thePdfAppearanceof a text or combo fieldString[]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.(package private) PdfAppearanceGet thePdfAppearanceof a list fieldGets a new list field.Gets the list of substitution fonts.private intgetTextAlignment(int runDirection) Flip text alignment for RTL texts Not sure why but this is neededGets a new text field.private int(package private) intstatic 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(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.private static inttextRunDirection(String ptext) private static inttextRunDirectionByContent(String ptext) Chose the run direction of a text field by it's contentprivate static inttextRunDirectionDefault(String ptext) private voidwriteMultipleValues(PdfFormField field, String[][] mix) Methods inherited from class 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 Details
-
defaultText
Holds value of property defaultText. -
choices
Holds value of property choices. -
choiceExports
Holds value of property choiceExports. -
choiceSelections
-
topFirst
private int topFirst -
extraMarginLeft
private float extraMarginLeft -
extraMarginTop
private float extraMarginTop -
substitutionFonts
-
extensionFont
Holds value of property extensionFont.
-
-
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
-
checkRTL
-
textRunDirectionDefault
-
textRunDirectionByContent
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
-
changeFontSize
-
removeCRLF
-
obfuscatePassword
-
composePhrase
-
getTextAlignment
private int getTextAlignment(int runDirection) Flip text alignment for RTL texts Not sure why but this is needed -
getAppearance
Get thePdfAppearanceof a text or combo field- Returns:
- A
PdfAppearance - Throws:
IOException- on errorDocumentException- on error
-
getListAppearance
Get thePdfAppearanceof 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:
IOExceptionDocumentException
-
writeMultipleValues
-
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
-
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
-
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
-
setSubstitutionFontList
-
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.
-