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
PdfObjectWrapper
thePdfObject
must be indirect.
-
-
Field Summary
Fields Modifier and Type Field Description protected NullableContainer<CheckBoxType>
checkType
private java.util.List<AbstractPdfFormField>
childFields
private java.lang.String
displayValue
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
private static java.util.Set<PdfName>
FORM_FIELD_KEYS
List of all allowable keys in form fields.protected ImageData
img
private static org.slf4j.Logger
LOGGER
protected java.lang.String
text
-
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 protected
PdfFormField(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
.protected
PdfFormField(PdfDocument pdfDocument)
Creates a minimalPdfFormField
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addAcroFormToCatalog()
PdfFormField
addKid(AbstractPdfFormField kid)
Adds a new kid to theKids
array property from aAbstractPdfFormField
.PdfFormField
addKid(AbstractPdfFormField kid, boolean throwExceptionOnError)
Adds a new kid to theKids
array property from aAbstractPdfFormField
.PdfFormField
addKid(PdfWidgetAnnotation kid)
Adds a new kid to theKids
array property from aPdfWidgetAnnotation
.private void
createKids(PdfDictionary pdfObject)
private static PdfString
generateDefaultAppearance(PdfName font, float fontSize, Color textColor)
private PdfObject
getAcroFormKey(PdfName key, int type)
PdfDictionary
getAdditionalAction()
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.PdfString
getAlternativeName()
Gets the current alternate name.java.lang.String[]
getAppearanceStates()
Gets the appearance state names.PdfFormField
getChildField(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 annotationsPdfFormAnnotation
of this form field.java.util.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.java.lang.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 annotationPdfFormAnnotation
.private PdfName
getFontNameFromDR(PdfDictionary fontResources, PdfObject font)
static java.util.Collection<PdfName>
getFormFieldKeys()
Gets a set of all possible form field keys exceptPdfName.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-justifiedPdfArray
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.private static PdfName
getTypeFromParent(PdfDictionary field)
private PdfName
getUniqueFontNameForDR(PdfDictionary fontResources)
PdfObject
getValue()
Gets the current value contained in the form field.java.lang.String
getValueAsString()
Gets the current value contained in the form field.java.util.List<PdfWidgetAnnotation>
getWidgets()
Gets allPdfWidgetAnnotation
that its children refer to.private boolean
hasDefaultAppearance()
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)
private boolean
mergeKidsIfKidWithSuchNameExists(AbstractPdfFormField newKid, boolean throwExceptionOnError)
private static TextAlignment
numberToHorizontalAlignment(int alignment)
(package private) static java.lang.String
optionsArrayToString(PdfArray options)
private void
putAcroFormObject(PdfName acroFormKey, PdfObject acroFormObject)
Puts object directly to AcroForm dictionary.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.(package private) void
replaceKids(java.util.Collection<AbstractPdfFormField> kids)
Replaces /Kids value with passed kids dictionaries, and keeps old flashed fields there.PdfFormField
setAdditionalAction(PdfName key, PdfAction action)
Sets an additional action for the form field.PdfFormField
setAlternativeName(java.lang.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'.(package private) AbstractPdfFormField
setChildField(AbstractPdfFormField kid)
Adds a field to the children of the current field.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(java.lang.String name)
Changes the name of the field to the specified value.private PdfFormField
setFieldValue(java.lang.String value, boolean generateAppearance)
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-justifiedPdfFormField
setMappingName(java.lang.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(java.lang.String value)
Sets a value to the field and generating field appearance if needed.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.PdfFormField
setValue(java.lang.String value, PdfFont font, float fontSize)
Set text field value with given font and size.PdfFormField
setValue(java.lang.String value, java.lang.String displayValue)
Sets the field value and the display string.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.void
updateDefaultAppearance()
Updates DA for Variable text, Push button and choice form fields.(package private) void
updateFontAndFontSize(PdfFont font, float fontSize)
-
Methods inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
disableCurrentFieldRegeneration, disableFieldRegeneration, enableCurrentFieldRegeneration, enableFieldRegeneration, equals, getAcroFormObject, getColor, getDocument, 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
. ThisPdfDictionary
must 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
- ThePdfDocument
instance.
-
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
- ThePdfDocument
instance.
-
-
Method Detail
-
createKids
private void createKids(PdfDictionary pdfObject)
-
makeFormField
public static PdfFormField makeFormField(PdfObject pdfObject, PdfDocument document)
Creates a (subtype of)PdfFormField
object. The type of the object depends on theFT
entry in thepdfObject
parameter.- Parameters:
pdfObject
- assumed to be either aPdfDictionary
, or aPdfIndirectReference
to aPdfDictionary
.document
- thePdfDocument
to create the field in.- Returns:
- a new
PdfFormField
, ornull
ifpdfObject
is not a form field.
-
makeFormFieldOrAnnotation
public static AbstractPdfFormField makeFormFieldOrAnnotation(PdfObject pdfObject, PdfDocument document)
- Parameters:
pdfObject
- assumed to be either aPdfDictionary
, or aPdfIndirectReference
to aPdfDictionary
.document
- thePdfDocument
to create the field in.- Returns:
- a new
AbstractPdfFormField
, ornull
ifpdfObject
is 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
.
-
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. Ifnull
thevalue
parameter 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
Kids
property, 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,null
is 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 theKids
array property from aAbstractPdfFormField
. Also sets the kid'sParent
property to this object.- Parameters:
kid
- a newAbstractPdfFormField
entry for the field'sKids
array property.- Returns:
- the edited
PdfFormField
.
-
addKid
public PdfFormField addKid(AbstractPdfFormField kid, boolean throwExceptionOnError)
Adds a new kid to theKids
array property from aAbstractPdfFormField
. Also sets the kid'sParent
property to this object.- Parameters:
kid
- a newAbstractPdfFormField
entry for the field'sKids
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.- Returns:
- the edited
PdfFormField
.
-
addKid
public PdfFormField addKid(PdfWidgetAnnotation kid)
Adds a new kid to theKids
array property from aPdfWidgetAnnotation
. Also sets the kid'sParent
property to this object.- Parameters:
kid
- a newPdfWidgetAnnotation
entry for the field'sKids
array 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
- anint
interpreted 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
- anint
interpreted 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
- anint
interpreted 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
- anint
interpreted 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 ofPdfString
objects 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 allPdfWidgetAnnotation
that its children refer to.- Returns:
- a list of
PdfWidgetAnnotation
.
-
getChildFormAnnotations
public java.util.List<PdfFormAnnotation> getChildFormAnnotations()
Gets all child form field's annotationsPdfFormAnnotation
of this form field.- Returns:
- a list of
PdfFormAnnotation
.
-
getFirstFormAnnotation
public PdfFormAnnotation getFirstFormAnnotation()
Gets a single child form field's annotationPdfFormAnnotation
.- Returns:
PdfFormAnnotation
or 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:
getDefaultAppearance
in 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 eitherPdfStream
orPdfString
.- 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. May be eitherPdfStream
orPdfString
.- 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 callregenerateField
method.- 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:
regenerateField
in 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:
true
if 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:
true
if 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:
getAppearanceStates
in 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:
release
in classAbstractPdfFormField
-
setColor
public AbstractPdfFormField setColor(Color color)
Sets the text color and regenerates appearance stream.- Overrides:
setColor
in classAbstractPdfFormField
- Parameters:
color
- the new value for the Color.- Returns:
- the edited
AbstractPdfFormField
.
-
updateFontAndFontSize
void updateFontAndFontSize(PdfFont font, float fontSize)
- Overrides:
updateFontAndFontSize
in 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()
-
-