public class PdfFormField extends AbstractPdfFormField
AcroForm.
To be able to be wrapped with this PdfObjectWrapper the PdfObject
must be indirect.
| Modifier and Type | Field and Description |
|---|---|
protected com.itextpdf.commons.datastructures.NullableContainer<CheckBoxType> |
checkType |
static int |
FF_MULTILINE
Flag that designates, if set, that the field can contain multiple lines
of text.
|
static int |
FF_NO_EXPORT
The NoExport flag, which specifies whether or not exporting is forbidden.
|
static int |
FF_PASSWORD
Flag that designates, if set, that the field's contents must be obfuscated.
|
static int |
FF_READ_ONLY
The ReadOnly flag, which specifies whether or not the field can be changed.
|
static int |
FF_REQUIRED
The Required flag, which specifies whether or not the field must be filled in.
|
protected PdfFormXObject |
form |
protected com.itextpdf.io.image.ImageData |
img |
protected String |
text |
color, DEFAULT_FONT_SIZE, font, fontSize, MIN_FONT_SIZE, parent, pdfAConformanceLevel| Modifier | Constructor and Description |
|---|---|
|
PdfFormField(PdfDictionary pdfObject)
Creates a form field as a wrapper object around a
PdfDictionary. |
protected |
PdfFormField(PdfDocument pdfDocument)
Creates a minimal
PdfFormField. |
protected |
PdfFormField(PdfWidgetAnnotation widget,
PdfDocument pdfDocument)
Creates a form field as a parent of a
PdfWidgetAnnotation. |
| Modifier and Type | Method and Description |
|---|---|
PdfFormField |
addKid(AbstractPdfFormField kid)
Adds a new kid to the
Kids array property from a
AbstractPdfFormField. |
PdfFormField |
addKid(AbstractPdfFormField kid,
boolean throwExceptionOnError)
Adds a new kid to the
Kids array property from a
AbstractPdfFormField. |
PdfFormField |
addKid(PdfWidgetAnnotation kid)
Adds a new kid to the
Kids array property from a
PdfWidgetAnnotation. |
PdfDictionary |
getAdditionalAction()
Gets the currently additional action dictionary for the form field.
|
List<AbstractPdfFormField> |
getAllChildFields()
Gets all childFields of this object, including the children of the children.
|
List<PdfFormField> |
getAllChildFormFields()
Gets all childFields of this object, including the children of the children
but not annotations.
|
PdfString |
getAlternativeName()
Gets the current alternate name.
|
String[] |
getAppearanceStates()
Gets the appearance state names.
|
PdfFormField |
getChildField(String fieldName)
Gets the child field of form field.
|
List<AbstractPdfFormField> |
getChildFields()
Gets the childFields of this object.
|
List<PdfFormAnnotation> |
getChildFormAnnotations()
Gets all child form field's annotations
PdfFormAnnotation of this form field. |
List<PdfFormField> |
getChildFormFields()
Gets all child form fields of this form field.
|
PdfString |
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.
|
PdfString |
getDefaultStyle()
Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.
|
PdfObject |
getDefaultValue()
Gets the default fallback value for the form field.
|
String |
getDisplayValue()
Gets the current display value of the form field.
|
boolean |
getFieldFlag(int flag)
Checks whether a certain flag, or any of a combination of flags, is set
for this form field.
|
int |
getFieldFlags()
Gets the current list of PDF form field flags.
|
PdfFormAnnotation |
getFirstFormAnnotation()
Gets a single child form field's annotation
PdfFormAnnotation. |
static Collection<PdfName> |
getFormFieldKeys()
Gets a set of all possible form field keys except
PdfName.Parent. |
PdfName |
getFormType()
Returns the type of the parent form field, or of the wrapped
<PdfDictionary> object.
|
static PdfName |
getFormType(PdfDictionary fieldDict)
Returns the type of the form field dictionary, or of the parent
<PdfDictionary> object.
|
TextAlignment |
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
|
PdfArray |
getKids()
Gets the kids of this object.
|
PdfString |
getMappingName()
Gets the current mapping name.
|
PdfArray |
getOptions()
Gets options for the form field.
|
PdfString |
getPartialFieldName()
Gets the current field partial name.
|
PdfObject |
getRichText()
Gets a rich text string, as described in "Rich Text Strings" section of Pdf spec.
|
PdfObject |
getValue()
Gets the current value contained in the form field.
|
String |
getValueAsString()
Gets the current value contained in the form field.
|
List<PdfWidgetAnnotation> |
getWidgets()
Gets all
PdfWidgetAnnotation that its children refer to. |
static boolean |
isFormField(PdfDictionary dict)
Checks if dictionary contains any of the form field keys.
|
boolean |
isInReadingMode()
Checks if the document that contains the field is created in reading mode.
|
boolean |
isMultiline()
If true, the field can contain multiple lines of text; if false, the field's text is restricted to a single line.
|
boolean |
isNoExport()
Gets the NoExport attribute.
|
boolean |
isPassword()
If true, the field is intended for entering a secure password that should not be echoed visibly to the screen.
|
boolean |
isReadOnly()
Gets the ReadOnly flag, specifying whether or not the field can be changed.
|
boolean |
isRequired()
Gets the Required flag, specifying whether or not the field must be filled in.
|
static int |
makeFieldFlag(int bitPosition)
Makes a field flag by bit position.
|
static PdfFormField |
makeFormField(PdfObject pdfObject,
PdfDocument document)
Creates a (subtype of)
PdfFormField object. |
static AbstractPdfFormField |
makeFormFieldOrAnnotation(PdfObject pdfObject,
PdfDocument document)
|
boolean |
regenerateField()
This method regenerates appearance stream of the field.
|
void |
release()
Releases underlying pdf object and other pdf entities used by wrapper.
|
void |
removeChild(AbstractPdfFormField fieldName)
Removes the childField object of this field.
|
void |
removeChildren()
Removes all children from the current field.
|
PdfFormField |
setAdditionalAction(PdfName key,
PdfAction action)
Sets an additional action for the form field.
|
PdfFormField |
setAlternativeName(String name)
Changes the alternate name of the field to the specified value.
|
PdfFormField |
setCheckType(CheckBoxType checkType)
Changes the type of graphical marker used to mark a checkbox as 'on'.
|
AbstractPdfFormField |
setColor(Color color)
Sets the text color and regenerates appearance stream.
|
PdfFormField |
setDefaultStyle(PdfString defaultStyleString)
Sets a default style string, as described in "Rich Text Strings" section of Pdf spec.
|
PdfFormField |
setDefaultValue(PdfObject value)
Sets the default fallback value for the form field.
|
PdfFormField |
setFieldFlag(int flag)
Adds a flag, or combination of flags, for the form field.
|
PdfFormField |
setFieldFlag(int flag,
boolean value)
Adds or removes a flag, or combination of flags, for the form field.
|
PdfFormField |
setFieldFlags(int flags)
Sets a flag, or combination of flags, for the form field.
|
PdfFormField |
setFieldName(String name)
Changes the name of the field to the specified value.
|
PdfFormField |
setJustification(TextAlignment justification)
Sets a code specifying the form of quadding (justification) to be used in displaying the text:
0 Left-justified
1 Centered
2 Right-justified
|
PdfFormField |
setMappingName(String name)
Changes the mapping name of the field to the specified value.
|
PdfFormField |
setNoExport(boolean noExport)
Sets the NoExport flag, specifying whether or not exporting is forbidden.
|
PdfFormField |
setOptions(PdfArray options)
Sets options for the form field.
|
PdfFormField |
setReadOnly(boolean readOnly)
Sets the ReadOnly flag, specifying whether or not the field can be changed.
|
PdfFormField |
setRequired(boolean required)
Sets the Required flag, specifying whether or not the field must be filled in.
|
PdfFormField |
setRichText(PdfObject richText)
Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec.
|
PdfFormField |
setValue(String value)
Sets a value to the field and generating field appearance if needed.
|
PdfFormField |
setValue(String value,
boolean generateAppearance)
Sets a value to the field (and fields with the same names) and generates field appearance if needed.
|
PdfFormField |
setValue(String value,
PdfFont font,
float fontSize)
Set text field value with given font and size.
|
PdfFormField |
setValue(String value,
String displayValue)
Sets the field value and the display string.
|
void |
updateDefaultAppearance()
Updates DA for Variable text, Push button and choice form fields.
|
disableCurrentFieldRegeneration, disableFieldRegeneration, enableCurrentFieldRegeneration, enableFieldRegeneration, equals, getColor, getDocument, getFieldName, getFont, getFontSize, getParent, getParentField, getPdfAConformanceLevel, getPdfObject, hashCode, isFieldRegenerationEnabled, isTerminalFormField, isWrappedObjectMustBeIndirect, put, remove, setFont, setFontAndSize, setFontSize, setFontSize, setFontSizeAutoScale, setParentensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidReleasepublic static final int FF_MULTILINE
public static final int FF_PASSWORD
public static final int FF_READ_ONLY
public static final int FF_REQUIRED
public static final int FF_NO_EXPORT
protected String text
protected com.itextpdf.io.image.ImageData img
protected PdfFormXObject form
protected com.itextpdf.commons.datastructures.NullableContainer<CheckBoxType> checkType
public PdfFormField(PdfDictionary pdfObject)
PdfDictionary.
This PdfDictionary must be an indirect object.pdfObject - the dictionary to be wrapped, must have an indirect reference.protected PdfFormField(PdfDocument pdfDocument)
PdfFormField.pdfDocument - The PdfDocument instance.protected PdfFormField(PdfWidgetAnnotation widget, PdfDocument pdfDocument)
PdfWidgetAnnotation.widget - The widget which will be a kid of the PdfFormField.pdfDocument - The PdfDocument instance.public static PdfFormField makeFormField(PdfObject pdfObject, PdfDocument document)
PdfFormField object. The type of the object
depends on the FT entry in the pdfObject parameter.pdfObject - assumed to be either a PdfDictionary, or a
PdfIndirectReference to a PdfDictionary.document - the PdfDocument to create the field in.PdfFormField, or null if
pdfObject is not a form field.public static AbstractPdfFormField makeFormFieldOrAnnotation(PdfObject pdfObject, PdfDocument document)
pdfObject - assumed to be either a PdfDictionary, or a
PdfIndirectReference to a PdfDictionary.document - the PdfDocument to create the field in.AbstractPdfFormField, or null if
pdfObject is not a form field and is not a widget annotation.public static int makeFieldFlag(int bitPosition)
bitPosition - bit position of a flag in range 1 to 32 from the pdf specification.public static boolean isFormField(PdfDictionary dict)
dict - field dictionary to check.public static Collection<PdfName> getFormFieldKeys()
PdfName.Parent.public static PdfName getFormType(PdfDictionary fieldDict)
fieldDict - field dictionary to get its type.PdfName.public PdfName getFormType()
PdfName.public PdfFormField setValue(String value)
value - of the field.public PdfFormField setValue(String value, boolean generateAppearance)
value - of the field.generateAppearance - if false, appearance won't be regenerated.public PdfFormField setValue(String value, PdfFont font, float fontSize)
value - text value.font - a PdfFont.fontSize - the size of the font.public PdfFormField setValue(String value, String displayValue)
value - the field value.displayValue - the string that is used for the appearance. If null
the value parameter will be used.public void removeChild(AbstractPdfFormField fieldName)
fieldName - a PdfFormField, that needs to be removed from form field children.public void removeChildren()
public PdfArray getKids()
Kids property, as a PdfArray.public List<AbstractPdfFormField> getChildFields()
public List<PdfFormField> getChildFormFields()
PdfFormField.public List<PdfFormField> getAllChildFormFields()
public List<AbstractPdfFormField> getAllChildFields()
public PdfFormField getChildField(String fieldName)
null is returned.fieldName - a String, name of the received field.PdfFormField.public PdfFormField addKid(AbstractPdfFormField kid)
Kids array property from a
AbstractPdfFormField. Also sets the kid's Parent property to this object.kid - a new AbstractPdfFormField entry for the field's Kids array property.PdfFormField.public PdfFormField addKid(AbstractPdfFormField kid, boolean throwExceptionOnError)
Kids array property from a
AbstractPdfFormField. Also sets the kid's Parent property to this object.kid - a new AbstractPdfFormField entry for the field's Kids array property.throwExceptionOnError - define whether exception (true) or log (false) is expected in case kid with
the same name exists and merge of two kids failed.PdfFormField.public PdfFormField addKid(PdfWidgetAnnotation kid)
Kids array property from a
PdfWidgetAnnotation. Also sets the kid's Parent property to this object.kid - a new PdfWidgetAnnotation entry for the field's Kids array property.PdfFormField.public PdfFormField setFieldName(String name)
name - the new field name, as a String.PdfFormField.public PdfString getPartialFieldName()
public PdfFormField setAlternativeName(String name)
name - the new alternate name, as a String.PdfFormField.public PdfString getAlternativeName()
PdfString.public PdfFormField setMappingName(String name)
name - the new alternate name, as a String.public PdfString getMappingName()
PdfString.public boolean getFieldFlag(int flag)
flag - an int interpreted as a series of a binary flags.public PdfFormField setFieldFlag(int flag)
setFieldFlags(int).flag - an int interpreted as a series of a binary flags.PdfFormField.public PdfFormField setFieldFlag(int flag, boolean value)
setFieldFlags(int).flag - an int interpreted as a series of a binary flags.value - if true, adds the flag(s). if false,
removes the flag(s).PdfFormField.public boolean isMultiline()
public boolean isPassword()
public PdfFormField setFieldFlags(int flags)
setFieldFlag(int)
which adds a flag to the existing flags.flags - an int interpreted as a series of a binary flags.PdfFormField.public int getFieldFlags()
int.public PdfObject getValue()
PdfObject.public String getValueAsString()
String.public String getDisplayValue()
public PdfFormField setDefaultValue(PdfObject value)
value - the default value.PdfFormField.public PdfObject getDefaultValue()
public PdfFormField setAdditionalAction(PdfName key, PdfAction action)
key - the dictionary key to use for storing the action.action - the action.PdfFormField.public PdfDictionary getAdditionalAction()
public PdfFormField setOptions(PdfArray options)
options - an array of PdfString objects that each represent
the 'on' state of one of the choices.PdfFormField.public PdfArray getOptions()
public List<PdfWidgetAnnotation> getWidgets()
PdfWidgetAnnotation that its children refer to.PdfWidgetAnnotation.public List<PdfFormAnnotation> getChildFormAnnotations()
PdfFormAnnotation of this form field.PdfFormAnnotation.public PdfFormAnnotation getFirstFormAnnotation()
PdfFormAnnotation.PdfFormAnnotation or null if there are no child annotations.public PdfString getDefaultAppearance()
getDefaultAppearance in class AbstractPdfFormFieldPdfString.public void updateDefaultAppearance()
public TextAlignment getJustification()
public PdfFormField setJustification(TextAlignment justification)
justification - the value to set the justification attribute to.PdfFormField.public PdfString getDefaultStyle()
PdfString.public PdfFormField setDefaultStyle(PdfString defaultStyleString)
defaultStyleString - a new default style for the form field.PdfFormField.public PdfObject getRichText()
PdfStream or PdfString.public PdfFormField setRichText(PdfObject richText)
PdfStream or PdfString.richText - a new rich text value.PdfFormField.public PdfFormField setCheckType(CheckBoxType checkType)
regenerateField method.checkType - the new checkbox marker.PdfFormField.public boolean regenerateField()
regenerateField in class AbstractPdfFormFieldpublic PdfFormField setReadOnly(boolean readOnly)
readOnly - if true, then the field cannot be changed.PdfFormField.public boolean isReadOnly()
true if the field cannot be changed.public PdfFormField setRequired(boolean required)
required - if true, then the field must be filled in.PdfFormField.public boolean isRequired()
true if the field must be filled in.public PdfFormField setNoExport(boolean noExport)
noExport - if true, then exporting is forbiddenPdfFormField.public boolean isNoExport()
public boolean isInReadingMode()
public String[] getAppearanceStates()
getAppearanceStates in class AbstractPdfFormFieldpublic void release()
PdfObject.release() if the wrapper is used.release in class AbstractPdfFormFieldpublic AbstractPdfFormField setColor(Color color)
setColor in class AbstractPdfFormFieldcolor - the new value for the Color.AbstractPdfFormField.Copyright © 1998–2023 Apryse Group NV. All rights reserved.