Package com.itextpdf.forms.fields
Class PdfFormField
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.forms.fields.AbstractPdfFormField
-
- com.itextpdf.forms.fields.PdfFormField
-
- Direct Known Subclasses:
PdfButtonFormField,PdfChoiceFormField,PdfSignatureFormField,PdfTextFormField
public class PdfFormField extends AbstractPdfFormField
This class represents a single field or field group in anAcroForm.To be able to be wrapped with this
PdfObjectWrapperthePdfObjectmust be indirect.
-
-
Field Summary
Fields Modifier and Type Field Description protected NullableContainer<CheckBoxType>checkTypeprivate java.util.List<AbstractPdfFormField>childFieldsprivate java.lang.StringdisplayValuestatic intFF_MULTILINEFlag that designates, if set, that the field can contain multiple lines of text.static intFF_NO_EXPORTThe NoExport flag, which specifies whether or not exporting is forbidden.static intFF_PASSWORDFlag that designates, if set, that the field's contents must be obfuscated.static intFF_READ_ONLYThe ReadOnly flag, which specifies whether or not the field can be changed.static intFF_REQUIREDThe Required flag, which specifies whether or not the field must be filled in.protected PdfFormXObjectformprivate static java.util.Set<PdfName>FORM_FIELD_KEYSList of all allowable keys in form fields.protected ImageDataimgprivate static org.slf4j.LoggerLOGGERprotected java.lang.Stringtext-
Fields inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
color, DEFAULT_FONT_SIZE, font, fontSize, MIN_FONT_SIZE, parent, pdfConformance
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPdfFormField(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAcroFormToCatalog()PdfFormFieldaddKid(AbstractPdfFormField kid)Adds a new kid to theKidsarray property from aAbstractPdfFormField.PdfFormFieldaddKid(AbstractPdfFormField kid, boolean throwExceptionOnError)Adds a new kid to theKidsarray property from aAbstractPdfFormField.PdfFormFieldaddKid(PdfWidgetAnnotation kid)Adds a new kid to theKidsarray property from aPdfWidgetAnnotation.static voidapplyAccessibilityProperties(PdfFormField formField, IAccessibleElement modelElement, PdfDocument pdfDocument)AppliesAccessibilityPropertiesfor provided form field and its annotation children.private voidcreateKids(PdfDictionary pdfObject)private static PdfStringgenerateDefaultAppearance(PdfName font, float fontSize, Color textColor)private PdfObjectgetAcroFormKey(PdfName key, int type)PdfDictionarygetAdditionalAction()Gets the currently additional action dictionary for the form field.java.util.List<AbstractPdfFormField>getAllChildFields()Gets all childFields of this object, including the children of the children.java.util.List<PdfFormField>getAllChildFormFields()Gets all childFields of this object, including the children of the children but not annotations.PdfStringgetAlternativeName()Gets the current alternate name.java.lang.String[]getAppearanceStates()Gets the appearance state names.PdfFormFieldgetChildField(java.lang.String fieldName)Gets the child field of form field.java.util.List<AbstractPdfFormField>getChildFields()Gets the childFields of this object.java.util.List<PdfFormAnnotation>getChildFormAnnotations()Gets all child form field's annotationsPdfFormAnnotationof this form field.java.util.List<PdfFormField>getChildFormFields()Gets all child form fields of this form field.PdfStringgetDefaultAppearance()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.PdfStringgetDefaultStyle()Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.PdfObjectgetDefaultValue()Gets the default fallback value for the form field.java.lang.StringgetDisplayValue()Gets the current display value of the form field.booleangetFieldFlag(int flag)Checks whether a certain flag, or any of a combination of flags, is set for this form field.intgetFieldFlags()Gets the current list of PDF form field flags.PdfFormAnnotationgetFirstFormAnnotation()Gets a single child form field's annotationPdfFormAnnotation.private PdfNamegetFontNameFromDR(PdfDictionary fontResources, PdfObject font)static java.util.Collection<PdfName>getFormFieldKeys()Gets a set of all possible form field keys exceptPdfName.Parent.PdfNamegetFormType()Returns the type of the parent form field, or of the wrapped <PdfDictionary> object.static PdfNamegetFormType(PdfDictionary fieldDict)Returns the type of the form field dictionary, or of the parent <PdfDictionary> object.TextAlignmentgetJustification()Gets a code specifying the form of quadding (justification) to be used in displaying the text: 0 Left-justified 1 Centered 2 Right-justifiedPdfArraygetKids()Gets the kids of this object.PdfStringgetMappingName()Gets the current mapping name.PdfArraygetOptions()Gets options for the form field.PdfStringgetPartialFieldName()Gets the current field partial name.PdfObjectgetRichText()Gets a rich text string, as described in "Rich Text Strings" section of Pdf spec.static java.lang.StringgetStringValue(PdfObject value)Retrieves string value fromPdfObjectrepresenting text string or text stream.private static PdfNamegetTypeFromParent(PdfDictionary field)private PdfNamegetUniqueFontNameForDR(PdfDictionary fontResources)PdfObjectgetValue()Gets the current value contained in the form field.java.lang.StringgetValueAsString()Gets the current value contained in the form field.java.util.List<PdfWidgetAnnotation>getWidgets()Gets allPdfWidgetAnnotationthat its children refer to.private booleanhasDefaultAppearance()static booleanisFormField(PdfDictionary dict)Checks if dictionary contains any of the form field keys.booleanisInReadingMode()Checks if the document that contains the field is created in reading mode.booleanisMultiline()If true, the field can contain multiple lines of text; if false, the field's text is restricted to a single line.booleanisNoExport()Gets the NoExport attribute.booleanisPassword()If true, the field is intended for entering a secure password that should not be echoed visibly to the screen.booleanisReadOnly()Gets the ReadOnly flag, specifying whether or not the field can be changed.booleanisRequired()Gets the Required flag, specifying whether or not the field must be filled in.static intmakeFieldFlag(int bitPosition)Makes a field flag by bit position.static PdfFormFieldmakeFormField(PdfObject pdfObject, PdfDocument document)Creates a (subtype of)PdfFormFieldobject.static AbstractPdfFormFieldmakeFormFieldOrAnnotation(PdfObject pdfObject, PdfDocument document)private booleanmergeKidsIfKidWithSuchNameExists(AbstractPdfFormField newKid, boolean throwExceptionOnError)private static TextAlignmentnumberToHorizontalAlignment(int alignment)(package private) static java.lang.StringoptionsArrayToString(PdfArray options)private voidputAcroFormObject(PdfName acroFormKey, PdfObject acroFormObject)Puts object directly to AcroForm dictionary.booleanregenerateField()This method regenerates appearance stream of the field.voidrelease()Releases underlying pdf object and other pdf entities used by wrapper.voidremoveChild(AbstractPdfFormField fieldName)Removes the childField object of this field.voidremoveChildren()Removes all children from the current field.(package private) voidreplaceKids(java.util.Collection<AbstractPdfFormField> kids)Replaces /Kids value with passed kids dictionaries, and keeps old flashed fields there.PdfFormFieldsetAdditionalAction(PdfName key, PdfAction action)Sets an additional action for the form field.PdfFormFieldsetAlternativeName(java.lang.String name)Changes the alternate name of the field to the specified value.PdfFormFieldsetCheckType(CheckBoxType checkType)Changes the type of graphical marker used to mark a checkbox as 'on'.(package private) AbstractPdfFormFieldsetChildField(AbstractPdfFormField kid)Adds a field to the children of the current field.AbstractPdfFormFieldsetColor(Color color)Sets the text color and regenerates appearance stream.PdfFormFieldsetDefaultStyle(PdfString defaultStyleString)Sets a default style string, as described in "Rich Text Strings" section of Pdf spec.PdfFormFieldsetDefaultValue(PdfObject value)Sets the default fallback value for the form field.PdfFormFieldsetFieldFlag(int flag)Adds a flag, or combination of flags, for the form field.PdfFormFieldsetFieldFlag(int flag, boolean value)Adds or removes a flag, or combination of flags, for the form field.PdfFormFieldsetFieldFlags(int flags)Sets a flag, or combination of flags, for the form field.PdfFormFieldsetFieldName(java.lang.String name)Changes the name of the field to the specified value.private PdfFormFieldsetFieldValue(java.lang.String value, boolean generateAppearance)PdfFormFieldsetJustification(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-justifiedPdfFormFieldsetMappingName(java.lang.String name)Changes the mapping name of the field to the specified value.PdfFormFieldsetNoExport(boolean noExport)Sets the NoExport flag, specifying whether or not exporting is forbidden.PdfFormFieldsetOptions(PdfArray options)Sets options for the form field.PdfFormFieldsetReadOnly(boolean readOnly)Sets the ReadOnly flag, specifying whether or not the field can be changed.PdfFormFieldsetRequired(boolean required)Sets the Required flag, specifying whether or not the field must be filled in.PdfFormFieldsetRichText(PdfObject richText)Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec.PdfFormFieldsetValue(java.lang.String value)Sets a value to the field and generating field appearance if needed.PdfFormFieldsetValue(java.lang.String value, boolean generateAppearance)Sets a value to the field (and fields with the same names) and generates field appearance if needed.PdfFormFieldsetValue(java.lang.String value, PdfFont font, float fontSize)Set text field value with given font and size.PdfFormFieldsetValue(java.lang.String value, java.lang.String displayValue)Sets the field value and the display string.private booleantryGenerateCheckboxAppearance(java.lang.String value)Distinguish mutually exclusive and regular checkboxes: check all the on states of the widgets, if they are not all equal, then consider that this checkbox is mutually exclusive and do nothing, otherwise regenerate normal appearance with value as on appearance state for all the widgets.voidupdateDefaultAppearance()Updates DA for Variable text, Push button and choice form fields.(package private) voidupdateFontAndFontSize(PdfFont font, float fontSize)-
Methods inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
disableCurrentFieldRegeneration, disableFieldRegeneration, enableCurrentFieldRegeneration, enableFieldRegeneration, equals, getAcroFormObject, getColor, getDocument, getFieldName, getFieldName, getFont, getFontSize, getParent, getParentField, getPdfConformance, getPdfObject, hashCode, isFieldRegenerationEnabled, isTerminalFormField, isWrappedObjectMustBeIndirect, put, remove, retrieveStyles, setColorNoRegenerate, setFont, setFontAndSize, setFontSize, setFontSize, setFontSizeAutoScale, setParent
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
FF_MULTILINE
public static final int FF_MULTILINE
Flag that designates, if set, that the field can contain multiple lines of text.
-
FF_PASSWORD
public static final int FF_PASSWORD
Flag that designates, if set, that the field's contents must be obfuscated.
-
FF_READ_ONLY
public static final int FF_READ_ONLY
The ReadOnly flag, which specifies whether or not the field can be changed.
-
FF_REQUIRED
public static final int FF_REQUIRED
The Required flag, which specifies whether or not the field must be filled in.
-
FF_NO_EXPORT
public static final int FF_NO_EXPORT
The NoExport flag, which specifies whether or not exporting is forbidden.
-
FORM_FIELD_KEYS
private static final java.util.Set<PdfName> FORM_FIELD_KEYS
List of all allowable keys in form fields.
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
text
protected java.lang.String text
-
img
protected ImageData img
-
form
protected PdfFormXObject form
-
checkType
protected NullableContainer<CheckBoxType> checkType
-
displayValue
private java.lang.String displayValue
-
childFields
private java.util.List<AbstractPdfFormField> childFields
-
-
Constructor Detail
-
PdfFormField
public PdfFormField(PdfDictionary pdfObject)
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
protected PdfFormField(PdfDocument pdfDocument)
Creates a minimalPdfFormField.- Parameters:
pdfDocument- ThePdfDocumentinstance.
-
PdfFormField
protected PdfFormField(PdfWidgetAnnotation widget, PdfDocument pdfDocument)
Creates a form field as a parent of aPdfWidgetAnnotation.- Parameters:
widget- The widget which will be a kid of thePdfFormField.pdfDocument- ThePdfDocumentinstance.
-
-
Method Detail
-
createKids
private void createKids(PdfDictionary pdfObject)
-
makeFormField
public static PdfFormField makeFormField(PdfObject pdfObject, PdfDocument document)
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, ornullifpdfObjectis not a form field.
-
makeFormFieldOrAnnotation
public static AbstractPdfFormField makeFormFieldOrAnnotation(PdfObject pdfObject, PdfDocument document)
- Parameters:
pdfObject- assumed to be either aPdfDictionary, or aPdfIndirectReferenceto aPdfDictionary.document- thePdfDocumentto create the field in.- Returns:
- a new
AbstractPdfFormField, ornullifpdfObjectis not a form field and is not a widget annotation.
-
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.
-
isFormField
public static boolean isFormField(PdfDictionary dict)
Checks if dictionary contains any of the form field keys.- Parameters:
dict- field dictionary to check.- Returns:
- true if it is a form field dictionary, false otherwise.
-
getFormFieldKeys
public static java.util.Collection<PdfName> getFormFieldKeys()
Gets a set of all possible form field keys exceptPdfName.Parent.- Returns:
- a set of form field keys.
-
getFormType
public static PdfName getFormType(PdfDictionary fieldDict)
Returns the type of the form field dictionary, or of the parent <PdfDictionary> object.- Parameters:
fieldDict- field dictionary to get its type.- Returns:
- the form type, as a
PdfName.
-
getStringValue
public static java.lang.String getStringValue(PdfObject value)
Retrieves string value fromPdfObjectrepresenting text string or text stream.- Parameters:
value-PdfObjectrepresenting text string or text stream- Returns:
Stringvalue
-
applyAccessibilityProperties
public static void applyAccessibilityProperties(PdfFormField formField, IAccessibleElement modelElement, PdfDocument pdfDocument)
AppliesAccessibilityPropertiesfor provided form field and its annotation children.- Parameters:
formField-PdfFormFieldthe form field to which the accessibility properties should be appliedmodelElement-IAccessibleElementthe form field layout element with accessibility propertiespdfDocument-PdfDocumentthe document to which the form field belongs
-
getFormType
public PdfName getFormType()
Returns the type of the parent form field, or of the wrapped <PdfDictionary> object.- Returns:
- the form type, as a
PdfName.
-
setValue
public PdfFormField setValue(java.lang.String value)
Sets a value to the field and generating field appearance if needed.- Parameters:
value- of the field.- Returns:
- the field.
-
setValue
public PdfFormField setValue(java.lang.String value, boolean generateAppearance)
Sets a value to the field (and fields with the same names) and generates field appearance if needed.- Parameters:
value- of the field.generateAppearance- if false, appearance won't be regenerated.- Returns:
- the field.
-
setValue
public PdfFormField setValue(java.lang.String value, PdfFont font, float fontSize)
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
public PdfFormField setValue(java.lang.String value, java.lang.String displayValue)
Sets the field value and the display string. The display string is used to build the appearance.- Parameters:
value- the field value.displayValue- the string that is used for the appearance. Ifnullthevalueparameter will be used.- Returns:
- the edited field.
-
removeChild
public void removeChild(AbstractPdfFormField fieldName)
Removes the childField object of this field.- Parameters:
fieldName- aPdfFormField, that needs to be removed from form field children.
-
removeChildren
public void removeChildren()
Removes all children from the current field.
-
getKids
public PdfArray getKids()
Gets the kids of this object.- Returns:
- contents of the dictionary's
Kidsproperty, as aPdfArray.
-
getChildFields
public java.util.List<AbstractPdfFormField> getChildFields()
Gets the childFields of this object.- Returns:
- the children of the current field.
-
getChildFormFields
public java.util.List<PdfFormField> getChildFormFields()
Gets all child form fields of this form field. Annotations are not returned.- Returns:
- a list of
PdfFormField.
-
getAllChildFormFields
public java.util.List<PdfFormField> getAllChildFormFields()
Gets all childFields of this object, including the children of the children but not annotations.- Returns:
- the children of the current field and their children.
-
getAllChildFields
public java.util.List<AbstractPdfFormField> getAllChildFields()
Gets all childFields of this object, including the children of the children.- Returns:
- the children of the current field and their children.
-
getChildField
public PdfFormField getChildField(java.lang.String fieldName)
Gets the child field of form field. If there is no child field with such name,nullis returned.- Parameters:
fieldName- aString, name of the received field.- Returns:
- the child of the current field as a
PdfFormField.
-
addKid
public PdfFormField addKid(AbstractPdfFormField kid)
Adds a new kid to theKidsarray property from aAbstractPdfFormField. Also sets the kid'sParentproperty to this object.- Parameters:
kid- a newAbstractPdfFormFieldentry for the field'sKidsarray property.- Returns:
- the edited
PdfFormField.
-
addKid
public PdfFormField addKid(AbstractPdfFormField kid, boolean throwExceptionOnError)
Adds a new kid to theKidsarray property from aAbstractPdfFormField. Also sets the kid'sParentproperty to this object.- Parameters:
kid- a newAbstractPdfFormFieldentry for the field'sKidsarray 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.- Returns:
- the edited
PdfFormField.
-
addKid
public PdfFormField addKid(PdfWidgetAnnotation kid)
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
PdfFormField.
-
setFieldName
public PdfFormField setFieldName(java.lang.String name)
Changes the name of the field to the specified value.- Parameters:
name- the new field name, as a String.- Returns:
- the edited
PdfFormField.
-
getPartialFieldName
public PdfString getPartialFieldName()
Gets the current field partial name.
-
setAlternativeName
public PdfFormField setAlternativeName(java.lang.String name)
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
PdfFormField.
-
getAlternativeName
public PdfString 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
public PdfFormField setMappingName(java.lang.String name)
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
public PdfString 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
public PdfFormField setFieldFlag(int flag)
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
PdfFormField.
-
setFieldFlag
public PdfFormField setFieldFlag(int flag, boolean value)
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
PdfFormField.
-
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
public PdfFormField setFieldFlags(int flags)
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
PdfFormField.
-
getFieldFlags
public int getFieldFlags()
Gets the current list of PDF form field flags.- Returns:
- the current list of flags, encoded as an
int.
-
getValue
public PdfObject getValue()
Gets the current value contained in the form field.- Returns:
- the current value, as a
PdfObject.
-
getValueAsString
public java.lang.String getValueAsString()
Gets the current value contained in the form field.- Returns:
- the current value, as a
String.
-
getDisplayValue
public java.lang.String getDisplayValue()
Gets the current display value of the form field.- Returns:
- the current display value, as a
String, if it exists. If not, returns the value as aString.
-
setDefaultValue
public PdfFormField setDefaultValue(PdfObject value)
Sets the default fallback value for the form field.- Parameters:
value- the default value.- Returns:
- the edited
PdfFormField.
-
getDefaultValue
public PdfObject getDefaultValue()
Gets the default fallback value for the form field.- Returns:
- the default value.
-
setAdditionalAction
public PdfFormField setAdditionalAction(PdfName key, PdfAction action)
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
PdfFormField.
-
getAdditionalAction
public PdfDictionary getAdditionalAction()
Gets the currently additional action dictionary for the form field.- Returns:
- the additional action dictionary.
-
setOptions
public PdfFormField setOptions(PdfArray options)
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
PdfFormField.
-
getOptions
public PdfArray getOptions()
Gets options for the form field. Should only return usable values for checkboxes and radio buttons.
-
getWidgets
public java.util.List<PdfWidgetAnnotation> getWidgets()
Gets allPdfWidgetAnnotationthat its children refer to.- Returns:
- a list of
PdfWidgetAnnotation.
-
getChildFormAnnotations
public java.util.List<PdfFormAnnotation> getChildFormAnnotations()
Gets all child form field's annotationsPdfFormAnnotationof this form field.- Returns:
- a list of
PdfFormAnnotation.
-
getFirstFormAnnotation
public PdfFormAnnotation getFirstFormAnnotation()
Gets a single child form field's annotationPdfFormAnnotation.- Returns:
PdfFormAnnotationor null if there are no child annotations.
-
getDefaultAppearance
public 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.- Specified by:
getDefaultAppearancein classAbstractPdfFormField- 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
public 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- Returns:
- the current justification attribute.
-
setJustification
public 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- Parameters:
justification- the value to set the justification attribute to.- Returns:
- the edited
PdfFormField.
-
getDefaultStyle
public PdfString getDefaultStyle()
Gets a default style string, as described in "Rich Text Strings" section of Pdf spec.- Returns:
- the default style, as a
PdfString.
-
setDefaultStyle
public PdfFormField setDefaultStyle(PdfString defaultStyleString)
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
PdfFormField.
-
getRichText
public PdfObject 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
public PdfFormField setRichText(PdfObject richText)
Sets a rich text string, as described in "Rich Text Strings" section of Pdf spec. It may be eitherPdfStreamorPdfString.- Parameters:
richText- a new rich text value- Returns:
- the edited
PdfFormField
-
setCheckType
public PdfFormField setCheckType(CheckBoxType checkType)
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
PdfFormField.
-
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.- Specified by:
regenerateFieldin classAbstractPdfFormField- Returns:
- whether or not the regeneration was successful.
-
setReadOnly
public PdfFormField setReadOnly(boolean readOnly)
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
PdfFormField.
-
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
public PdfFormField setRequired(boolean required)
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
PdfFormField.
-
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
public PdfFormField setNoExport(boolean noExport)
Sets the NoExport flag, specifying whether or not exporting is forbidden.- Parameters:
noExport- iftrue, then exporting is forbidden- Returns:
- the edited
PdfFormField.
-
isNoExport
public boolean isNoExport()
Gets the NoExport attribute.- Returns:
- whether exporting the value following a form action is forbidden.
-
isInReadingMode
public boolean isInReadingMode()
Checks if the document that contains the field is created in reading mode.- Returns:
- true if reading mode is used, false otherwise.
-
getAppearanceStates
public java.lang.String[] getAppearanceStates()
Gets the appearance state names.- Specified by:
getAppearanceStatesin classAbstractPdfFormField- Returns:
- an array of Strings containing the names of the appearance states.
-
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.- Overrides:
releasein classAbstractPdfFormField
-
setColor
public AbstractPdfFormField setColor(Color color)
Sets the text color and regenerates appearance stream.- Overrides:
setColorin classAbstractPdfFormField- Parameters:
color- the new value for the Color.- Returns:
- the edited
AbstractPdfFormField.
-
updateFontAndFontSize
void updateFontAndFontSize(PdfFont font, float fontSize)
- Overrides:
updateFontAndFontSizein classAbstractPdfFormField
-
optionsArrayToString
static java.lang.String optionsArrayToString(PdfArray options)
-
setChildField
AbstractPdfFormField setChildField(AbstractPdfFormField kid)
Adds a field to the children of the current field.- Parameters:
kid- the field, which should become a child.- Returns:
- the kid itself.
-
replaceKids
void replaceKids(java.util.Collection<AbstractPdfFormField> kids)
Replaces /Kids value with passed kids dictionaries, and keeps old flashed fields there. Also updates childFields array forPdfFormField.- Parameters:
kids- collection of new kids.
-
generateDefaultAppearance
private static PdfString generateDefaultAppearance(PdfName font, float fontSize, Color textColor)
-
getTypeFromParent
private static PdfName getTypeFromParent(PdfDictionary field)
-
numberToHorizontalAlignment
private static TextAlignment numberToHorizontalAlignment(int alignment)
-
setFieldValue
private PdfFormField setFieldValue(java.lang.String value, boolean generateAppearance)
-
tryGenerateCheckboxAppearance
private boolean tryGenerateCheckboxAppearance(java.lang.String value)
Distinguish mutually exclusive and regular checkboxes: check all the on states of the widgets, if they are not all equal, then consider that this checkbox is mutually exclusive and do nothing, otherwise regenerate normal appearance with value as on appearance state for all the widgets.- Parameters:
value- not empty value different from "Off".
-
mergeKidsIfKidWithSuchNameExists
private boolean mergeKidsIfKidWithSuchNameExists(AbstractPdfFormField newKid, boolean throwExceptionOnError)
-
hasDefaultAppearance
private boolean hasDefaultAppearance()
-
getUniqueFontNameForDR
private PdfName getUniqueFontNameForDR(PdfDictionary fontResources)
-
getFontNameFromDR
private PdfName getFontNameFromDR(PdfDictionary fontResources, PdfObject font)
-
putAcroFormObject
private void putAcroFormObject(PdfName acroFormKey, PdfObject acroFormObject)
Puts object directly to AcroForm dictionary. It works much faster than consequent invocation ofPdfAcroForm.getAcroForm(PdfDocument, boolean)andPdfObjectWrapper.getPdfObject().Note, this method assume that Catalog already has AcroForm object.
addAcroFormToCatalog()should be called explicitly.- Parameters:
acroFormKey- the key of the object.acroFormObject- the object to add.
-
addAcroFormToCatalog
private void addAcroFormToCatalog()
-
-