Package com.itextpdf.forms.fields
Class PdfFormField
- Direct Known Subclasses:
-
PdfButtonFormField,PdfChoiceFormField,PdfSignatureFormField,PdfTextFormField
This class represents a single field or field group in an
AcroForm.
To be able to be wrapped with this PdfObjectWrapper the PdfObject must be indirect.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intprotected Colorprotected Colorprotected floatprotected intprotected Colorstatic final intFlag that designates, if set, that the field can contain multiple lines of text.static final intstatic final intFlag that designates, if set, that the field's contents must be obfuscated.static final intstatic final intprotected PdfFontprotected floatprotected PdfFormXObjectstatic final intstatic final intprotected ImageDataprotected PdfAConformanceLevelprotected intprotected Stringstatic final intA field with the symbol checkstatic final intA field with the symbol circlestatic final intA field with the symbol crossstatic final intA field with the symbol diamondstatic final intA field with the symbol squarestatic final intA field with the symbol starstatic final intstatic final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPdfFormField(PdfWidgetAnnotation widget, PdfDocument pdfDocument) Creates a form field as a parent of aPdfWidgetAnnotation.PdfFormField(PdfDictionary pdfObject) Creates a form field as a wrapper object around aPdfDictionary.protectedPdfFormField(PdfDocument pdfDocument) Creates a minimalPdfFormField. -
Method Summary
Modifier and TypeMethodDescriptionaddKid(PdfFormField kid) Adds a new kid to theKidsarray property from aPdfFormField.Adds a new kid to theKidsarray property from aPdfWidgetAnnotation.static PdfButtonFormFieldcreateButton(PdfDocument doc, int flags) Creates an emptybutton form fieldwith custom behavior and layout.static PdfButtonFormFieldcreateButton(PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptybutton form fieldwith custom behavior and layout.static PdfButtonFormFieldcreateButton(PdfDocument doc, Rectangle rect, int flags) Creates an emptybutton form fieldwith custom behavior and layout, on a specified location.static PdfButtonFormFieldcreateButton(PdfDocument doc, Rectangle rect, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptybutton form fieldwith custom behavior and layout, on a specified location.static PdfButtonFormFieldcreateCheckBox(PdfDocument doc, Rectangle rect, String name, String value) Creates aPdfButtonFormFieldas a checkbox.static PdfButtonFormFieldcreateCheckBox(PdfDocument doc, Rectangle rect, String name, String value, int checkType) Creates aPdfButtonFormFieldas a checkbox.static PdfButtonFormFieldcreateCheckBox(PdfDocument doc, Rectangle rect, String name, String value, int checkType, PdfAConformanceLevel pdfAConformanceLevel) Creates aPdfButtonFormFieldas a checkbox.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, int flags) Creates an emptychoice form field.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptychoice form field.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, Rectangle rect, int flags) Creates an emptychoice form fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags) Creates achoice form fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates achoice form fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags) Creates achoice form fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates achoice form fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[] options) Creates acomboboxwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[][] options) Creates acomboboxwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates acomboboxwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates acomboboxwith custom behavior and layout, on a specified location.static PdfFormFieldCreates an empty form field without a predefined set of layout or behavior.static PdfFormFieldcreateEmptyField(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an empty form field without a predefined set of layout or behavior.static PdfChoiceFormFieldcreateList(PdfDocument doc, Rectangle rect, String name, String value, String[] options) Creates alist fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateList(PdfDocument doc, Rectangle rect, String name, String value, String[][] options) Creates alist fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateList(PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates alist fieldwith custom behavior and layout, on a specified location.static PdfChoiceFormFieldcreateList(PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates alist fieldwith custom behavior and layout, on a specified location.static PdfTextFormFieldcreateMultilineText(PdfDocument doc, Rectangle rect, String name, String value) Creates a namedmultiline text form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().static PdfTextFormFieldcreateMultilineText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize) Creates a namedmultilined text form fieldwith an initial value, with a specified font and font size.static PdfButtonFormFieldcreatePushButton(PdfDocument doc, Rectangle rect, String name, String caption) Creates aPdfButtonFormFieldas a push button without data.static PdfButtonFormFieldcreatePushButton(PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize) Creates aPdfButtonFormFieldas a push button without data, with its caption in a custom font.static PdfButtonFormFieldcreatePushButton(PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize, PdfAConformanceLevel pdfAConformanceLevel) Creates aPdfButtonFormFieldas a push button without data, with its caption in a custom font.static PdfFormFieldcreateRadioButton(PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value) Creates a genericPdfFormFieldthat is added to a radio group.static PdfFormFieldcreateRadioButton(PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value, PdfAConformanceLevel pdfAConformanceLevel) Creates a genericPdfFormFieldthat is added to a radio group.static PdfButtonFormFieldcreateRadioGroup(PdfDocument doc, String name, String value) Creates aradio group form field.static PdfButtonFormFieldcreateRadioGroup(PdfDocument doc, String name, String value, PdfAConformanceLevel pdfAConformanceLevel) Creates aradio group form field.static PdfSignatureFormFieldCreates an emptysignature form field.static PdfSignatureFormFieldcreateSignature(PdfDocument doc, Rectangle rect) Creates an emptysignature form field.static PdfSignatureFormFieldcreateSignature(PdfDocument doc, Rectangle rect, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptysignature form field.static PdfSignatureFormFieldcreateSignature(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptysignature form field.static PdfTextFormFieldcreateText(PdfDocument doc) Creates an emptytext form field.static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect) Creates an emptytext form field.static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect, String name) Creates a namedtext form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect, String name, String value) Creates a namedtext form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize) Creates a namedtext form fieldwith an initial value, with a specified font and font size.static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline) Creates a namedtext form fieldwith an initial value, with a specified font and font size.static PdfTextFormFieldcreateText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline, PdfAConformanceLevel pdfAConformanceLevel) Creates a namedtext form fieldwith an initial value, with a specified font and font size.static PdfTextFormFieldcreateText(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptytext form field.protected voiddrawBorder(PdfCanvas canvas, PdfFormXObject xObject, float width, float height) Draws a border using the borderWidth and borderColor of the form field.protected voiddrawButton(PdfCanvas canvas, float x, float y, float width, float height, String text, PdfFont font, float fontSize) Performs the low-level drawing operations to draw a button object.protected voiddrawCheckAppearance(float width, float height, String onStateName) Draws the appearance of a checkbox with a specified state value.protected voiddrawCheckBox(PdfCanvas canvas, float width, float height, float fontSize) Performs the low-level drawing operations to draw a checkbox object.protected voiddrawMultiLineTextAppearance(Rectangle rect, PdfFont font, String value, PdfFormXObject appearance) protected voiddrawPdfA2CheckAppearance(float width, float height, String onStateName, int checkType) Draws PDF/A-2 compliant check appearance.protected voiddrawPdfACheckBox(PdfCanvas canvas, float width, float height, boolean on) protected PdfFormXObjectdrawPushButtonAppearance(float width, float height, String text, PdfFont font, float fontSize) Draws the appearance for a push button.protected voiddrawRadioAppearance(float width, float height, String value) Draws the appearance of a radio button with a specified value.protected voiddrawRadioBorder(PdfCanvas canvas, PdfFormXObject xObject, float width, float height) protected voiddrawRadioField(PdfCanvas canvas, float width, float height, boolean on) Draws a radio button.protected voiddrawTextAppearance(Rectangle rect, PdfFont font, float fontSize, String value, PdfFormXObject appearance) Draws the visual appearance of text in a form field.Gets the currently additional action dictionary for the form field.Gets the current alternate name.String[]Gets the appearance state names.floatGets the border width for the field.getColor()Gets the current color of the form field.Gets default appearance string containing a sequence of valid page-content graphics or text state operators that define such properties as the field's text size and color.Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.Gets the default fallback value for the form field.protected PdfDocumentGets thePdfDocumentthat owns that form field.booleangetFieldFlag(int flag) Checks whether a certain flag, or any of a combination of flags, is set for this form field.intGets the current list of PDF form field flags.Gets the current field name.getFont()Gets the current font of the form field.floatGets the current fontSize of the form field.Returns the type of the parent form field, or of the wrappedobject. Gets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justifiedgetKids()Gets the kids of this object.Gets the current mapping name.Gets options for the form field.Gets the parent dictionary.protected RectanglegetRect(PdfDictionary field) Gets aRectanglethat matches the current size and position of this form field.Gets a rich text string, as described in "Rich Text Strings" section of Pdf spec.getValue()Gets the current value contained in the form field.Gets the current value contained in the form field.Gets allPdfWidgetAnnotationthat this form field and itskidsrefer to.booleanIf true, the field can contain multiple lines of text; if false, the field's text is restricted to a single line.booleanGets the NoExport attribute.booleanIf true, the field is intended for entering a secure password that should not be echoed visibly to the screen.booleanGets the ReadOnly flag, specifying whether or not the field can be changed.booleanGets the Required flag, specifying whether or not the field must be filled in.protected booleanDefines if the object behind this wrapper must be an indirect object in the resultant document.static intmakeFieldFlag(int bitPosition) Makes a field flag by bit position.static PdfFormFieldmakeFormField(PdfObject pdfObject, PdfDocument document) Creates a (subtype of)PdfFormFieldobject.protected static PdfArrayprocessOptions(String[] options) protected static PdfArrayprocessOptions(String[][] options) Inserts the value into thePdfDictionaryof this field and associates it with the specified key.booleanThis method regenerates appearance stream of the field.voidrelease()Releases underlying pdf object and other pdf entities used by wrapper.Removes the specified key from thePdfDictionaryof this field.Sets the action on allwidgetsof this form field.setAdditionalAction(PdfName key, PdfAction action) Sets an additional action for the form field.setAlternativeName(String name) Changes the alternate name of the field to the specified value.setAppearance(PdfName appearanceType, String appearanceState, PdfStream appearanceStream) Sets an appearance for (the widgets related to) the form field.setBackgroundColor(Color backgroundColor) Basic setter for thebackgroundColorproperty.setBorderColor(Color color) Sets the Border Color.setBorderStyle(PdfDictionary style) Sets the border style for the field.setBorderWidth(float borderWidth) Sets the border width for the field.setCheckType(int checkType) Changes the type of graphical marker used to mark a checkbox as 'on'.Sets the text color.setDefaultStyle(PdfString defaultStyleString) Sets a default style string, as described in "Rich Text Strings" section of Pdf spec.setDefaultValue(PdfObject value) Sets the default fallback value for the form field.setFieldFlag(int flag) Adds a flag, or combination of flags, for the form field.setFieldFlag(int flag, boolean value) Adds or removes a flag, or combination of flags, for the form field.setFieldFlags(int flags) Sets a flag, or combination of flags, for the form field.setFieldName(String name) Changes the name of the field to the specified value.Basic setter for thefontproperty.setFontAndSize(PdfFont font, float fontSize) Combined setter for thefontandfontSizeproperties.setFontSize(float fontSize) Basic setter for thefontSizeproperty.setFontSize(int fontSize) Basic setter for thefontSizeproperty.Sets zero font size which will be interpreted as auto-size according to ISO 32000-1, 12.7.3.3.setJustification(int justification) Sets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justifiedsetMappingName(String name) Changes the mapping name of the field to the specified value.setNoExport(boolean noExport) Sets the NoExport flag, specifying whether or not exporting is forbidden.setOptions(PdfArray options) Sets options for the form field.setPage(int pageNum) Specifies on which page the form field's widget must be shown.setParent(PdfFormField parent) Sets a parentPdfFormFieldfor the current object.setReadOnly(boolean readOnly) Sets the ReadOnly flag, specifying whether or not the field can be changed.setRequired(boolean required) Sets the Required flag, specifying whether or not the field must be filled in.setRichText(PdfObject richText) Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec.setRotation(int degRotation) Basic setter for thedegRotationproperty.Sets a value to the field and generating field appearance if needed.Sets a value to the field and generates field appearance if needed.Set text field value with given font and sizeSets the field value and the display string.setVisibility(int visibility) Set the visibility flags of the form field annotation Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINTprotected static Object[]voidUpdates DA for Variable text, Push button and choice form fields.Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Field Details
-
FF_MULTILINE
public static final int FF_MULTILINEFlag that designates, if set, that the field can contain multiple lines of text. -
FF_PASSWORD
public static final int FF_PASSWORDFlag that designates, if set, that the field's contents must be obfuscated. -
ALIGN_LEFT
public static final int ALIGN_LEFT- See Also:
-
ALIGN_CENTER
public static final int ALIGN_CENTER- See Also:
-
ALIGN_RIGHT
public static final int ALIGN_RIGHT- See Also:
-
TYPE_CHECK
public static final int TYPE_CHECKA field with the symbol check- See Also:
-
TYPE_CIRCLE
public static final int TYPE_CIRCLEA field with the symbol circle- See Also:
-
TYPE_CROSS
public static final int TYPE_CROSSA field with the symbol cross- See Also:
-
TYPE_DIAMOND
public static final int TYPE_DIAMONDA field with the symbol diamond- See Also:
-
TYPE_SQUARE
public static final int TYPE_SQUAREA field with the symbol square- See Also:
-
TYPE_STAR
public static final int TYPE_STARA field with the symbol star- See Also:
-
HIDDEN
public static final int HIDDEN- See Also:
-
VISIBLE_BUT_DOES_NOT_PRINT
public static final int VISIBLE_BUT_DOES_NOT_PRINT- See Also:
-
HIDDEN_BUT_PRINTABLE
public static final int HIDDEN_BUT_PRINTABLE- See Also:
-
VISIBLE
public static final int VISIBLE- See Also:
-
FF_READ_ONLY
public static final int FF_READ_ONLY -
FF_REQUIRED
public static final int FF_REQUIRED -
FF_NO_EXPORT
public static final int FF_NO_EXPORT -
text
-
img
-
font
-
fontSize
protected float fontSize -
color
-
checkType
protected int checkType -
borderWidth
protected float borderWidth -
backgroundColor
-
borderColor
-
rotation
protected int rotation -
form
-
pdfAConformanceLevel
-
-
Constructor Details
-
PdfFormField
Creates a form field as a wrapper object around aPdfDictionary. ThisPdfDictionarymust be an indirect object.- Parameters:
-
pdfObject- the dictionary to be wrapped, must have an indirect reference.
-
PdfFormField
Creates a minimalPdfFormField.- Parameters:
-
pdfDocument- The document
-
PdfFormField
Creates a form field as a parent of aPdfWidgetAnnotation.- Parameters:
-
widget- The widget which will be a kid of thePdfFormField -
pdfDocument- The document
-
-
Method Details
-
makeFieldFlag
public static int makeFieldFlag(int bitPosition) Makes a field flag by bit position. Bit positions are numbered 1 to 32. But position 0 corresponds to flag 1, position 3 corresponds to flag 4 etc.- Parameters:
-
bitPosition- bit position of a flag in range 1 to 32 from the pdf specification. - Returns:
- corresponding field flag.
-
createEmptyField
Creates an empty form field without a predefined set of layout or behavior.- Parameters:
-
doc- thePdfDocumentto create the field in - Returns:
-
a new
PdfFormField
-
createEmptyField
public static PdfFormField createEmptyField(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an empty form field without a predefined set of layout or behavior.- Parameters:
-
doc- thePdfDocumentto create the field in -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfFormField
-
createButton
Creates an emptybutton form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the button field in -
rect- the location on the page for the button -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfButtonFormField
-
createButton
public static PdfButtonFormField createButton(PdfDocument doc, Rectangle rect, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptybutton form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the button field in -
rect- the location on the page for the button -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfButtonFormField
-
createButton
Creates an emptybutton form fieldwith custom behavior and layout.- Parameters:
-
doc- thePdfDocumentto create the button field in -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfButtonFormField
-
createButton
public static PdfButtonFormField createButton(PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptybutton form fieldwith custom behavior and layout.- Parameters:
-
doc- thePdfDocumentto create the button field in -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfButtonFormField
-
createText
Creates an emptytext form field.- Parameters:
-
doc- thePdfDocumentto create the text field in - Returns:
-
a new
PdfTextFormField
-
createText
public static PdfTextFormField createText(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptytext form field.- Parameters:
-
doc- thePdfDocumentto create the text field in -
pdfAConformanceLevel- the desiredPdfAConformanceLevelof the field. Must match the conformance level of thePdfDocumentthis field will eventually be added into - Returns:
-
a new
PdfTextFormField
-
createText
Creates an emptytext form field.- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field - Returns:
-
a new
PdfTextFormField
-
createText
Creates a namedtext form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field - Returns:
-
a new
PdfTextFormField
-
createText
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, String name, String value) Creates a namedtext form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value - Returns:
-
a new
PdfTextFormField
-
createText
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize) Creates a namedtext form fieldwith an initial value, with a specified font and font size.- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font - Returns:
-
a new
PdfTextFormField
-
createText
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline) Creates a namedtext form fieldwith an initial value, with a specified font and font size.- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font -
multiline- true for multiline text field - Returns:
-
a new
PdfTextFormField
-
createText
public static PdfTextFormField createText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, boolean multiline, PdfAConformanceLevel pdfAConformanceLevel) Creates a namedtext form fieldwith an initial value, with a specified font and font size.- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font -
multiline- true for multiline text field -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfTextFormField
-
createMultilineText
public static PdfTextFormField createMultilineText(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize) Creates a namedmultilined text form fieldwith an initial value, with a specified font and font size.- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font - Returns:
-
a new
PdfTextFormField
-
createMultilineText
public static PdfTextFormField createMultilineText(PdfDocument doc, Rectangle rect, String name, String value) Creates a namedmultiline text form fieldwith an initial value, and the form's default font specified inPdfAcroForm.getDefaultResources().- Parameters:
-
doc- thePdfDocumentto create the text field in -
rect- the location on the page for the text field -
name- the name of the form field -
value- the initial value - Returns:
-
a new
PdfTextFormField
-
createChoice
Creates an emptychoice form field.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfChoiceFormField
-
createChoice
public static PdfChoiceFormField createChoice(PdfDocument doc, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptychoice form field.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormField
-
createChoice
Creates an emptychoice form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfChoiceFormField
-
createChoice
public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags) Creates achoice form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
options- an array ofPdfStringobjects that each represent the 'on' state of one of the choices. -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfChoiceFormField
-
createChoice
public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfArray options, int flags, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates achoice form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
options- an array ofPdfStringobjects that each represent the 'on' state of one of the choices. -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. -
font- the desired font to be used when displaying the text -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormField
-
createChoice
public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags) Creates achoice form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font -
options- an array ofPdfStringobjects that each represent the 'on' state of one of the choices. -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. - Returns:
-
a new
PdfChoiceFormField
-
createChoice
public static PdfChoiceFormField createChoice(PdfDocument doc, Rectangle rect, String name, String value, PdfFont font, float fontSize, PdfArray options, int flags, PdfAConformanceLevel pdfAConformanceLevel) Creates achoice form fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
font- aPdfFont -
fontSize- the size of the font -
options- an array ofPdfStringobjects that each represent the 'on' state of one of the choices. -
flags- anint, containing a set of binary behavioral flags. Do binaryORon thisintto set the flags you require. -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormField
-
createSignature
Creates an emptysignature form field.- Parameters:
-
doc- thePdfDocumentto create the signature field in - Returns:
-
a new
PdfSignatureFormField
-
createSignature
public static PdfSignatureFormField createSignature(PdfDocument doc, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptysignature form field.- Parameters:
-
doc- thePdfDocumentto create the signature field in -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfSignatureFormField
-
createSignature
Creates an emptysignature form field.- Parameters:
-
doc- thePdfDocumentto create the signature field in -
rect- the location on the page for the signature field - Returns:
-
a new
PdfSignatureFormField
-
createSignature
public static PdfSignatureFormField createSignature(PdfDocument doc, Rectangle rect, PdfAConformanceLevel pdfAConformanceLevel) Creates an emptysignature form field.- Parameters:
-
doc- thePdfDocumentto create the signature field in -
rect- the location on the page for the signature field -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfSignatureFormField
-
createRadioGroup
Creates aradio group form field.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
name- the name of the form field -
value- the initial value - Returns:
-
a new
radio group
-
createRadioGroup
public static PdfButtonFormField createRadioGroup(PdfDocument doc, String name, String value, PdfAConformanceLevel pdfAConformanceLevel) Creates aradio group form field.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
name- the name of the form field -
value- the initial value -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
radio group
-
createRadioButton
public static PdfFormField createRadioButton(PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value) Creates a genericPdfFormFieldthat is added to a radio group.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
radioGroup- the radio button group that this field should belong to -
value- the initial value - Returns:
-
a new
PdfFormField - See Also:
-
createRadioButton
public static PdfFormField createRadioButton(PdfDocument doc, Rectangle rect, PdfButtonFormField radioGroup, String value, PdfAConformanceLevel pdfAConformanceLevel) Creates a genericPdfFormFieldthat is added to a radio group.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
radioGroup- the radio button group that this field should belong to -
value- the initial value -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfFormField - See Also:
-
createPushButton
public static PdfButtonFormField createPushButton(PdfDocument doc, Rectangle rect, String name, String caption) Creates aPdfButtonFormFieldas a push button without data.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
caption- the text to display on the button - Returns:
-
a new
PdfButtonFormField
-
createPushButton
public static PdfButtonFormField createPushButton(PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize) Creates aPdfButtonFormFieldas a push button without data, with its caption in a custom font.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
caption- the text to display on the button -
font- aPdfFont -
fontSize- the size of the font - Returns:
-
a new
PdfButtonFormField
-
createPushButton
public static PdfButtonFormField createPushButton(PdfDocument doc, Rectangle rect, String name, String caption, PdfFont font, float fontSize, PdfAConformanceLevel pdfAConformanceLevel) Creates aPdfButtonFormFieldas a push button without data, with its caption in a custom font.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
caption- the text to display on the button -
font- aPdfFont -
fontSize- the size of the font -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfButtonFormField
-
createCheckBox
public static PdfButtonFormField createCheckBox(PdfDocument doc, Rectangle rect, String name, String value) Creates aPdfButtonFormFieldas a checkbox.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
value- the initial value - Returns:
-
a new
checkbox
-
createCheckBox
public static PdfButtonFormField createCheckBox(PdfDocument doc, Rectangle rect, String name, String value, int checkType) Creates aPdfButtonFormFieldas a checkbox.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
value- the initial value -
checkType- the type of checkbox graphic to use. - Returns:
-
a new
checkbox
-
createCheckBox
public static PdfButtonFormField createCheckBox(PdfDocument doc, Rectangle rect, String name, String value, int checkType, PdfAConformanceLevel pdfAConformanceLevel) Creates aPdfButtonFormFieldas a checkbox. Check symbol will fit rectangle. You may set font and font size after creation.- Parameters:
-
doc- thePdfDocumentto create the radio group in -
rect- the location on the page for the field -
name- the name of the form field -
value- the initial value -
checkType- the type of checkbox graphic to use. -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
checkbox
-
createComboBox
public static PdfChoiceFormField createComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[][] options) Creates acomboboxwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the combobox in -
rect- the location on the page for the combobox -
name- the name of the form field -
value- the initial value -
options- a two-dimensional array of Strings which will be converted to a PdfArray. - Returns:
-
a new
PdfChoiceFormFieldas a combobox
-
createComboBox
public static PdfChoiceFormField createComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates acomboboxwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the combobox in -
rect- the location on the page for the combobox -
name- the name of the form field -
value- the initial value -
options- a two-dimensional array of Strings which will be converted to a PdfArray. -
font- the desired font to be used when displaying the text -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormFieldas a combobox
-
createComboBox
public static PdfChoiceFormField createComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[] options) Creates acomboboxwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the combobox in -
rect- the location on the page for the combobox -
name- the name of the form field -
value- the initial value -
options- an array of Strings which will be converted to a PdfArray. - Returns:
-
a new
PdfChoiceFormFieldas a combobox
-
createComboBox
public static PdfChoiceFormField createComboBox(PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates acomboboxwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the combobox in -
rect- the location on the page for the combobox -
name- the name of the form field -
value- the initial value -
options- an array of Strings which will be converted to a PdfArray. -
font- the desired font to be used when displaying the text -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormFieldas a combobox
-
createList
public static PdfChoiceFormField createList(PdfDocument doc, Rectangle rect, String name, String value, String[][] options) Creates alist fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
options- a two-dimensional array of Strings which will be converted to a PdfArray. - Returns:
-
a new
PdfChoiceFormFieldas a list field
-
createList
public static PdfChoiceFormField createList(PdfDocument doc, Rectangle rect, String name, String value, String[][] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates alist fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the choice field in -
rect- the location on the page for the choice field -
name- the name of the form field -
value- the initial value -
options- a two-dimensional array of Strings which will be converted to a PdfArray. -
font- the desired font to be used when displaying the text -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormFieldas a list field
-
createList
public static PdfChoiceFormField createList(PdfDocument doc, Rectangle rect, String name, String value, String[] options) Creates alist fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the list field in -
rect- the location on the page for the list field -
name- the name of the form field -
value- the initial value -
options- an array of Strings which will be converted to a PdfArray. - Returns:
-
a new
PdfChoiceFormFieldas a list field
-
createList
public static PdfChoiceFormField createList(PdfDocument doc, Rectangle rect, String name, String value, String[] options, PdfFont font, PdfAConformanceLevel pdfAConformanceLevel) Creates alist fieldwith custom behavior and layout, on a specified location.- Parameters:
-
doc- thePdfDocumentto create the list field in -
rect- the location on the page for the list field -
name- the name of the form field -
value- the initial value -
options- an array of Strings which will be converted to a PdfArray. -
font- the desired font to be used when displaying the text -
pdfAConformanceLevel- thePdfAConformanceLevelof the document. null if it's no PDF/A document - Returns:
-
a new
PdfChoiceFormFieldas a list field
-
makeFormField
Creates a (subtype of)PdfFormFieldobject. The type of the object depends on theFTentry in thepdfObjectparameter.- Parameters:
-
pdfObject- assumed to be either aPdfDictionary, or aPdfIndirectReferenceto aPdfDictionary -
document- thePdfDocumentto create the field in - Returns:
-
a new
PdfFormField, ornullifpdfObjectdoes not contain aFTentry
-
getFormType
Returns the type of the parent form field, or of the wrappedobject. - Returns:
-
the form type, as a
PdfName
-
setValue
Sets a value to the field and generating field appearance if needed.- Parameters:
-
value- of the field - Returns:
- the field
-
setValue
Sets a value to the field and generates field appearance if needed.- Parameters:
-
value- of the field -
generateAppearance- if false, appearance won't be regenerated - Returns:
- the field
-
setValue
Set text field value with given font and size- Parameters:
-
value- text value -
font- aPdfFont -
fontSize- the size of the font - Returns:
- the edited field
-
setValue
Sets the field value and the display string. The display string is used to build the appearance.- Parameters:
-
value- the field value -
display- the string that is used for the appearance. Ifnullthevalueparameter will be used - Returns:
- the edited field
-
setParent
Sets a parentPdfFormFieldfor the current object.- Parameters:
-
parent- another form field that this field belongs to, usually a group field - Returns:
- the edited field
-
getParent
Gets the parent dictionary.- Returns:
- another form field that this field belongs to, usually a group field
-
getKids
Gets the kids of this object.- Returns:
-
contents of the dictionary's
Kidsproperty, as aPdfArray
-
addKid
Adds a new kid to theKidsarray property from aPdfFormField. Also sets the kid'sParentproperty to this object.- Parameters:
-
kid- a newPdfFormFieldentry for the field'sKidsarray property - Returns:
- the edited field
-
addKid
Adds a new kid to theKidsarray property from aPdfWidgetAnnotation. Also sets the kid'sParentproperty to this object.- Parameters:
-
kid- a newPdfWidgetAnnotationentry for the field'sKidsarray property - Returns:
- the edited field
-
setFieldName
Changes the name of the field to the specified value.- Parameters:
-
name- the new field name, as a String - Returns:
- the edited field
-
getFieldName
Gets the current field name.- Returns:
-
the current field name, as a
PdfString
-
setAlternativeName
Changes the alternate name of the field to the specified value. The alternate is a descriptive name to be used by status messages etc.- Parameters:
-
name- the new alternate name, as a String - Returns:
- the edited field
-
getAlternativeName
Gets the current alternate name. The alternate is a descriptive name to be used by status messages etc.- Returns:
-
the current alternate name, as a
PdfString
-
setMappingName
Changes the mapping name of the field to the specified value. The mapping name can be used when exporting the form data in the document.- Parameters:
-
name- the new alternate name, as a String - Returns:
- the edited field
-
getMappingName
Gets the current mapping name. The mapping name can be used when exporting the form data in the document.- Returns:
-
the current mapping name, as a
PdfString
-
getFieldFlag
public boolean getFieldFlag(int flag) Checks whether a certain flag, or any of a combination of flags, is set for this form field.- Parameters:
-
flag- anintinterpreted as a series of a binary flags - Returns:
- true if any of the flags specified in the parameter is also set in the form field.
-
setFieldFlag
Adds a flag, or combination of flags, for the form field. This method is intended to be used one flag at a time, but this is not technically enforced. To replace the current value, usesetFieldFlags(int).- Parameters:
-
flag- anintinterpreted as a series of a binary flags - Returns:
- the edited field
-
setFieldFlag
Adds or removes a flag, or combination of flags, for the form field. This method is intended to be used one flag at a time, but this is not technically enforced. To replace the current value, usesetFieldFlags(int).- Parameters:
-
flag- anintinterpreted as a series of a binary flags -
value- iftrue, adds the flag(s). iffalse, removes the flag(s). - Returns:
- the edited field
-
isMultiline
public boolean isMultiline()If true, the field can contain multiple lines of text; if false, the field's text is restricted to a single line.- Returns:
- whether the field can span over multiple lines.
-
isPassword
public boolean isPassword()If true, the field is intended for entering a secure password that should not be echoed visibly to the screen. Characters typed from the keyboard should instead be echoed in some unreadable form, such as asterisks or bullet characters.- Returns:
- whether or not the contents of the field must be obfuscated
-
setFieldFlags
Sets a flag, or combination of flags, for the form field. This method replaces the previous value. Compare withsetFieldFlag(int)which adds a flag to the existing flags.- Parameters:
-
flags- anintinterpreted as a series of a binary flags - Returns:
- the edited field
-
getFieldFlags
public int getFieldFlags()Gets the current list of PDF form field flags.- Returns:
-
the current list of flags, encoded as an
int
-
getValue
Gets the current value contained in the form field.- Returns:
-
the current value, as a
PdfObject
-
getValueAsString
Gets the current value contained in the form field.- Returns:
-
the current value, as a
String
-
setDefaultValue
Sets the default fallback value for the form field.- Parameters:
-
value- the default value - Returns:
- the edited field
-
getDefaultValue
Gets the default fallback value for the form field.- Returns:
- the default value
-
setAdditionalAction
Sets an additional action for the form field.- Parameters:
-
key- the dictionary key to use for storing the action -
action- the action - Returns:
- the edited field
-
getAdditionalAction
Gets the currently additional action dictionary for the form field.- Returns:
- the additional action dictionary
-
setOptions
Sets options for the form field. Only to be used for checkboxes and radio buttons.- Parameters:
-
options- an array ofPdfStringobjects that each represent the 'on' state of one of the choices. - Returns:
- the edited field
-
getOptions
Gets options for the form field. Should only return usable values for checkboxes and radio buttons. -
getWidgets
Gets allPdfWidgetAnnotationthat this form field and itskidsrefer to.- Returns:
-
a list of
PdfWidgetAnnotation
-
getDefaultAppearance
Gets default appearance string containing a sequence of valid page-content graphics or text state operators that define such properties as the field's text size and color.- Returns:
-
the default appearance graphics, as a
PdfString
-
updateDefaultAppearance
public void updateDefaultAppearance()Updates DA for Variable text, Push button and choice form fields. The resources required for DA will be put to AcroForm's DR. Note, for other form field types DA will be removed. -
getJustification
Gets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justified- Returns:
- the current justification attribute
-
setJustification
Sets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justified- Parameters:
-
justification- the value to set the justification attribute to - Returns:
- the edited field
-
getDefaultStyle
Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.- Returns:
-
the default style, as a
PdfString
-
setDefaultStyle
Sets a default style string, as described in "Rich Text Strings" section of Pdf spec.- Parameters:
-
defaultStyleString- a new default style for the form field - Returns:
- the edited field
-
getRichText
Gets a rich text string, as described in "Rich Text Strings" section of Pdf spec. May be eitherPdfStreamorPdfString.- Returns:
- the current rich text value
-
setRichText
Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec. May be eitherPdfStreamorPdfString.- Parameters:
-
richText- a new rich text value - Returns:
- The edited PdfFormField
-
getFontSize
public float getFontSize()Gets the current fontSize of the form field.- Returns:
- the current fontSize
-
getFont
Gets the current font of the form field.- Returns:
-
the current
font
-
getColor
Gets the current color of the form field.- Returns:
-
the current
color
-
setFont
Basic setter for thefontproperty. Regenerates the field appearance after setting the new value. Note that the font will be added to the document so ensure that the font is embedded if it's a pdf/a document.- Parameters:
-
font- The new font to be set - Returns:
- The edited PdfFormField
-
setFontSize
Basic setter for thefontSizeproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
fontSize- The new font size to be set - Returns:
- The edited PdfFormField
-
setFontSize
Basic setter for thefontSizeproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
fontSize- The new font size to be set - Returns:
- The edited PdfFormField
-
setFontAndSize
Combined setter for thefontandfontSizeproperties. Regenerates the field appearance after setting the new value.- Parameters:
-
font- The new font to be set -
fontSize- The new font size to be set - Returns:
- The edited PdfFormField
-
setBackgroundColor
Basic setter for thebackgroundColorproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
backgroundColor- The new color to be set ornullif no background needed - Returns:
- The edited PdfFormField
-
setRotation
Basic setter for thedegRotationproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
degRotation- The new degRotation to be set - Returns:
- The edited PdfFormField
-
setAction
Sets the action on allwidgetsof this form field.- Parameters:
-
action- The action - Returns:
- The edited field
-
setCheckType
Changes the type of graphical marker used to mark a checkbox as 'on'. Notice that in order to complete the change one should callregenerateFieldmethod- Parameters:
-
checkType- the new checkbox marker - Returns:
- The edited field
-
setVisibility
Set the visibility flags of the form field annotation Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT- Parameters:
-
visibility- visibility option - Returns:
- The edited field
-
regenerateField
public boolean regenerateField()This method regenerates appearance stream of the field. Use it if you changed any field parameters and didn't use setValue method which generates appearance by itself.- Returns:
- whether or not the regeneration was successful.
-
getBorderWidth
public float getBorderWidth()Gets the border width for the field.- Returns:
- the current border width.
-
setBorderWidth
Sets the border width for the field.- Parameters:
-
borderWidth- The new border width. - Returns:
- The edited field
-
setBorderStyle
Sets the border style for the field.- Parameters:
-
style- the new border style. - Returns:
- the edited field
-
setBorderColor
Sets the Border Color.- Parameters:
-
color- the new value for the Border Color - Returns:
- the edited field
-
setColor
Sets the text color.- Parameters:
-
color- the new value for the Color - Returns:
- the edited field
-
setReadOnly
Sets the ReadOnly flag, specifying whether or not the field can be changed.- Parameters:
-
readOnly- iftrue, then the field cannot be changed. - Returns:
- the edited field
-
isReadOnly
public boolean isReadOnly()Gets the ReadOnly flag, specifying whether or not the field can be changed.- Returns:
-
trueif the field cannot be changed.
-
setRequired
Sets the Required flag, specifying whether or not the field must be filled in.- Parameters:
-
required- iftrue, then the field must be filled in. - Returns:
- the edited field
-
isRequired
public boolean isRequired()Gets the Required flag, specifying whether or not the field must be filled in.- Returns:
-
trueif the field must be filled in.
-
setNoExport
Sets the NoExport flag, specifying whether or not exporting is forbidden.- Parameters:
-
noExport- iftrue, then exporting is forbidden - Returns:
- the edited field
-
isNoExport
public boolean isNoExport()Gets the NoExport attribute.- Returns:
- whether exporting the value following a form action is forbidden.
-
setPage
Specifies on which page the form field's widget must be shown.- Parameters:
-
pageNum- the page number - Returns:
- the edited field
-
getAppearanceStates
Gets the appearance state names.- Returns:
- an array of Strings containing the names of the appearance states
-
setAppearance
public PdfFormField setAppearance(PdfName appearanceType, String appearanceState, PdfStream appearanceStream) Sets an appearance for (the widgets related to) the form field.- Parameters:
-
appearanceType- the type of appearance stream to be added- PdfName.N: normal appearance
- PdfName.R: rollover appearance
- PdfName.D: down appearance
-
appearanceState- the state of the form field that needs to be true for the appearance to be used. Differentiates between several streams of the same type. -
appearanceStream- the appearance instructions, as aPdfStream - Returns:
- the edited field
-
setFontSizeAutoScale
Sets zero font size which will be interpreted as auto-size according to ISO 32000-1, 12.7.3.3.- Returns:
- the edited field
-
put
Inserts the value into thePdfDictionaryof this field and associates it with the specified key. If the key is already present in this field dictionary, this method will override the old value with the specified one.- Parameters:
-
key- key to insert or to override -
value- the value to associate with the specified key - Returns:
-
this
PdfFormFieldinstance
-
remove
Removes the specified key from thePdfDictionaryof this field.- Parameters:
-
key- key to be removed - Returns:
-
this
PdfFormFieldinstance
-
release
public void release()Releases underlying pdf object and other pdf entities used by wrapper. This method should be called instead of direct call toPdfObject.release()if the wrapper is used. -
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Description copied from class:PdfObjectWrapperDefines if the object behind this wrapper must be an indirect object in the resultant document.
If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.
Return value of this method shouldn't depend on any logic, it should return always true or false.- Specified by:
-
isWrappedObjectMustBeIndirectin classPdfObjectWrapper<PdfDictionary> - Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
getDocument
Gets thePdfDocumentthat owns that form field.- Returns:
-
the
PdfDocumentthat owns that form field.
-
getRect
Gets aRectanglethat matches the current size and position of this form field.- Parameters:
-
field- current form field. - Returns:
-
a
Rectanglethat matches the current size and position of this form field.
-
processOptions
- Parameters:
-
options- Two-dimensional array of options. - Returns:
-
a
PdfArraythat contains all the options.
-
processOptions
- Parameters:
-
options- array of options. - Returns:
-
a
PdfArraythat contains all the options.
-
splitDAelements
-
drawTextAppearance
protected void drawTextAppearance(Rectangle rect, PdfFont font, float fontSize, String value, PdfFormXObject appearance) Draws the visual appearance of text in a form field.- Parameters:
-
rect- The location on the page for the list field -
font- aPdfFont -
fontSize- The size of the font -
value- The initial value -
appearance- The appearance
-
drawMultiLineTextAppearance
protected void drawMultiLineTextAppearance(Rectangle rect, PdfFont font, String value, PdfFormXObject appearance) -
drawBorder
Draws a border using the borderWidth and borderColor of the form field.- Parameters:
-
canvas- ThePdfCanvason which to draw -
xObject- The PdfFormXObject -
width- The width of the rectangle to draw -
height- The height of the rectangle to draw
-
drawRadioBorder
protected void drawRadioBorder(PdfCanvas canvas, PdfFormXObject xObject, float width, float height) -
drawRadioAppearance
Draws the appearance of a radio button with a specified value.- Parameters:
-
width- the width of the radio button to draw -
height- the height of the radio button to draw -
value- the value of the button
-
drawRadioField
Draws a radio button.- Parameters:
-
canvas- thePdfCanvason which to draw -
width- the width of the radio button to draw -
height- the height of the radio button to draw -
on- required to betruefor fulfilling the drawing operation
-
drawCheckAppearance
Draws the appearance of a checkbox with a specified state value.- Parameters:
-
width- the width of the checkbox to draw -
height- the height of the checkbox to draw -
onStateName- the state of the form field that will be drawn
-
drawPdfA2CheckAppearance
protected void drawPdfA2CheckAppearance(float width, float height, String onStateName, int checkType) Draws PDF/A-2 compliant check appearance. Actually it's just PdfA check appearance. According to corrigendum there is no difference between them- Parameters:
-
width- width of the checkbox -
height- height of the checkbox -
onStateName- name that corresponds to the "On" state of the checkbox -
checkType- the type that determines how the checkbox will look like. Allowed values areTYPE_CHECK,TYPE_CIRCLE,TYPE_CROSS,TYPE_DIAMOND,TYPE_SQUARE,TYPE_STAR
-
drawPushButtonAppearance
protected PdfFormXObject drawPushButtonAppearance(float width, float height, String text, PdfFont font, float fontSize) Draws the appearance for a push button.- Parameters:
-
width- the width of the pushbutton -
height- the width of the pushbutton -
text- the text to display on the button -
font- aPdfFont -
fontSize- the size of the font - Returns:
-
a new
PdfFormXObject
-
drawButton
protected void drawButton(PdfCanvas canvas, float x, float y, float width, float height, String text, PdfFont font, float fontSize) Performs the low-level drawing operations to draw a button object.- Parameters:
-
canvas- thePdfCanvasof the page to draw on. -
x- will be ignored, according to spec it shall be 0 -
y- will be ignored, according to spec it shall be 0 -
width- the width of the button -
height- the width of the button -
text- the text to display on the button -
font- aPdfFont -
fontSize- the size of the font
-
drawCheckBox
Performs the low-level drawing operations to draw a checkbox object.- Parameters:
-
canvas- thePdfCanvasof the page to draw on. -
width- the width of the button -
height- the width of the button -
fontSize- the size of the font
-
drawPdfACheckBox
-