Package com.itextpdf.forms.fields
Class AbstractPdfFormField
java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
com.itextpdf.forms.fields.AbstractPdfFormField
- Direct Known Subclasses:
-
PdfFormAnnotation,PdfFormField
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 TypeFieldDescriptionprotected Colorstatic final intSize of text in form fields when font size is not explicitly set.protected PdfFontprotected floatstatic final intMinimal size of text in form fields.protected PdfFormFieldParent form field.protected PdfConformance -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPdfFormField(PdfDictionary pdfObject) Creates a form field as a wrapper object around aPdfDictionary. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method disables regeneration of the current field appearance stream.voidThis method disables regeneration of the field and its children appearance stream.voidThis method enables regeneration of the current field appearance stream and regenerates it.voidThis method enables regeneration of the field appearance stream.booleanIndicate whether some other object is "equal to" this one.abstract String[]Gets the appearance state names.getColor()Gets the current color of the form field.abstract PdfStringGets 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 thePdfDocumentthat owns that form field.Gets the current field name.getFont()Gets the current font of the form field.floatGets the current fontSize of the form field.Gets the parent dictionary.Gets the parent field.Gets the declared conformance.Gets the wrapped dictionary.inthashCode()Generate a hash code for this object.booleanThis method checks if field appearance stream regeneration is enabled.booleanDetermines whether current form field is terminal or not.protected booleanDefines if the object behind this wrapper must be an indirect object in the resultant document.Inserts the value into thePdfDictionaryof this field and associates it with the specified key.abstract 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 text color and regenerates appearance stream.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.voidsetParent(PdfFormField parent) Sets a parentPdfFormFieldfor the current object.Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Field Details
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZESize of text in form fields when font size is not explicitly set.- See Also:
-
MIN_FONT_SIZE
public static final int MIN_FONT_SIZEMinimal size of text in form fields.- See Also:
-
font
-
fontSize
protected float fontSize -
color
-
pdfConformance
-
parent
Parent form field.
-
-
Constructor Details
-
AbstractPdfFormField
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.
-
-
Method Details
-
getPdfObject
Gets the wrapped dictionary.- Overrides:
-
getPdfObjectin classPdfObjectWrapper<PdfDictionary> - Returns:
- the wrapped dictionary.
-
setParent
Sets a parentPdfFormFieldfor the current object.- Parameters:
-
parent- another form field that this field belongs to, usually a group field.
-
getParent
Gets the parent dictionary.- Returns:
- another form field that this field belongs to.
-
getParentField
Gets the parent field.- Returns:
- another form field that this field belongs to.
-
getFieldName
Gets the current field name.- Returns:
-
the current field name, as a
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.- Returns:
-
the default appearance graphics, as a
PdfString.
-
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
-
getPdfConformance
Gets the declared conformance.- Returns:
-
the
PdfConformance
-
regenerateField
public abstract 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.
-
disableFieldRegeneration
public void disableFieldRegeneration()This method disables regeneration of the field and its children appearance stream. So all of its children in the hierarchy will also not be regenerated.Note that after this method is called field will be regenerated only during
enableFieldRegeneration()call. -
enableFieldRegeneration
public void enableFieldRegeneration()This method enables regeneration of the field appearance stream. Please note that this method enables regeneration for the children of the field. Also, appearance will be regenerated during this method call.Should be called after
disableFieldRegeneration()method call. -
disableCurrentFieldRegeneration
public void disableCurrentFieldRegeneration()This method disables regeneration of the current field appearance stream. -
enableCurrentFieldRegeneration
public void enableCurrentFieldRegeneration()This method enables regeneration of the current field appearance stream and regenerates it. -
isFieldRegenerationEnabled
public boolean isFieldRegenerationEnabled()This method checks if field appearance stream regeneration is enabled.- Returns:
- true if regeneration is enabled for this field (and all of its ancestors), false otherwise.
-
getAppearanceStates
Gets the appearance state names.- Returns:
- an array of Strings containing the names of the appearance states.
-
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:
- the edited field.
-
remove
Removes the specified key from thePdfDictionaryof this field.- Parameters:
-
key- key to be removed. - Returns:
- the edited field.
-
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. -
getDocument
Gets thePdfDocumentthat owns that form field.- Returns:
-
the
PdfDocumentthat owns that form field.
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Defines 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.
-
setColor
Sets the text color and regenerates appearance stream.- Parameters:
-
color- the new value for the Color. - Returns:
-
the edited
AbstractPdfFormField.
-
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
AbstractPdfFormField.
-
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
AbstractPdfFormField.
-
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
AbstractPdfFormField.
-
setFontSizeAutoScale
Sets zero font size which will be interpreted as auto-size according to ISO 32000-1, 12.7.3.3.- Returns:
-
the edited
AbstractPdfFormField.
-
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
AbstractPdfFormField.
-
isTerminalFormField
public boolean isTerminalFormField()Determines whether current form field is terminal or not.- Returns:
- true if this form field is a terminal one, false otherwise.
-
equals
Indicate whether some other object is "equal to" this one. Compares wrapped objects. -
hashCode
public int hashCode()Generate a hash code for this object.
-