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
public abstract class AbstractPdfFormField extends PdfObjectWrapper<PdfDictionary>
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 Color
color
private static int
DA_COLOR
Index of color value in default appearance element.private static int
DA_FONT
Index of font value in default appearance element.private static int
DA_SIZE
Index of font size value in default appearance element.static int
DEFAULT_FONT_SIZE
Size of text in form fields when font size is not explicitly set.private boolean
enableFieldRegeneration
Indicates if the form field appearance stream regeneration is enabled.protected PdfFont
font
protected float
fontSize
static int
MIN_FONT_SIZE
Minimal size of text in form fields.protected PdfFormField
parent
Parent form field.protected PdfConformance
pdfConformance
private static PdfName[]
TERMINAL_FIELDS
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPdfFormField(PdfDictionary pdfObject)
Creates a form field as a wrapper object around aPdfDictionary
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
disableCurrentFieldRegeneration()
This method disables regeneration of the current field appearance stream.void
disableFieldRegeneration()
This method disables regeneration of the field and its children appearance stream.void
enableCurrentFieldRegeneration()
This method enables regeneration of the current field appearance stream and regenerates it.void
enableFieldRegeneration()
This method enables regeneration of the field appearance stream.boolean
equals(java.lang.Object o)
Indicate whether some other object is "equal to" this one.(package private) PdfObject
getAcroFormObject(PdfName key, int type)
abstract java.lang.String[]
getAppearanceStates()
Gets the appearance state names.Color
getColor()
Gets the current color of the form field.abstract 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.PdfDocument
getDocument()
Gets thePdfDocument
that owns that form field.PdfString
getFieldName()
Gets the current field name.PdfFont
getFont()
Gets the current font of the form field.float
getFontSize()
Gets the current fontSize of the form field.PdfDictionary
getParent()
Gets the parent dictionary.PdfFormField
getParentField()
Gets the parent field.PdfConformance
getPdfConformance()
Gets the declared conformance.PdfDictionary
getPdfObject()
Gets the wrapped dictionary.int
hashCode()
Generate a hash code for this object.boolean
isFieldRegenerationEnabled()
This method checks if field appearance stream regeneration is enabled.boolean
isTerminalFormField()
Determines whether current form field is terminal or not.protected boolean
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.AbstractPdfFormField
put(PdfName key, PdfObject value)
Inserts the value into thePdfDictionary
of this field and associates it with the specified key.abstract boolean
regenerateField()
This method regenerates appearance stream of the field.void
release()
Releases underlying pdf object and other pdf entities used by wrapper.AbstractPdfFormField
remove(PdfName key)
Removes the specified key from thePdfDictionary
of this field.private PdfFont
resolveFontName(java.lang.String fontName)
(package private) void
retrieveStyles()
AbstractPdfFormField
setColor(Color color)
Sets the text color and regenerates appearance stream.(package private) void
setColorNoRegenerate(Color color)
Sets the text color and does not regenerate appearance stream.AbstractPdfFormField
setFont(PdfFont font)
Basic setter for thefont
property.AbstractPdfFormField
setFontAndSize(PdfFont font, float fontSize)
Combined setter for thefont
andfontSize
properties.AbstractPdfFormField
setFontSize(float fontSize)
Basic setter for thefontSize
property.AbstractPdfFormField
setFontSize(int fontSize)
Basic setter for thefontSize
property.AbstractPdfFormField
setFontSizeAutoScale()
Sets zero font size which will be interpreted as auto-size according to ISO 32000-1, 12.7.3.3.void
setParent(PdfFormField parent)
Sets a parentPdfFormField
for the current object.private static java.lang.Object[]
splitDAelements(java.lang.String da)
(package private) void
updateFontAndFontSize(PdfFont font, float fontSize)
-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZE
Size of text in form fields when font size is not explicitly set.- See Also:
- Constant Field Values
-
MIN_FONT_SIZE
public static final int MIN_FONT_SIZE
Minimal size of text in form fields.- See Also:
- Constant Field Values
-
TERMINAL_FIELDS
private static final PdfName[] TERMINAL_FIELDS
-
DA_FONT
private static final int DA_FONT
Index of font value in default appearance element.- See Also:
- Constant Field Values
-
DA_SIZE
private static final int DA_SIZE
Index of font size value in default appearance element.- See Also:
- Constant Field Values
-
DA_COLOR
private static final int DA_COLOR
Index of color value in default appearance element.- See Also:
- Constant Field Values
-
font
protected PdfFont font
-
fontSize
protected float fontSize
-
color
protected Color color
-
pdfConformance
protected PdfConformance pdfConformance
-
parent
protected PdfFormField parent
Parent form field.
-
enableFieldRegeneration
private boolean enableFieldRegeneration
Indicates if the form field appearance stream regeneration is enabled.
-
-
Constructor Detail
-
AbstractPdfFormField
protected AbstractPdfFormField(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.
-
-
Method Detail
-
getPdfObject
public PdfDictionary getPdfObject()
Gets the wrapped dictionary.- Overrides:
getPdfObject
in classPdfObjectWrapper<PdfDictionary>
- Returns:
- the wrapped dictionary.
-
setParent
public void setParent(PdfFormField parent)
Sets a parentPdfFormField
for the current object.- Parameters:
parent
- another form field that this field belongs to, usually a group field.
-
getParent
public PdfDictionary getParent()
Gets the parent dictionary.- Returns:
- another form field that this field belongs to.
-
getParentField
public PdfFormField getParentField()
Gets the parent field.- Returns:
- another form field that this field belongs to.
-
getFieldName
public PdfString getFieldName()
Gets the current field name.- Returns:
- the current field name, as a
PdfString
.
-
getDefaultAppearance
public abstract 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.
-
getColor
public Color getColor()
Gets the current color of the form field.- Returns:
- the current
color
-
getPdfConformance
public PdfConformance 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.
-
setColorNoRegenerate
void setColorNoRegenerate(Color color)
Sets the text color and does not regenerate appearance stream.- Parameters:
color
- the new value for the Color.
-
getAppearanceStates
public abstract java.lang.String[] getAppearanceStates()
Gets the appearance state names.- Returns:
- an array of Strings containing the names of the appearance states.
-
put
public AbstractPdfFormField put(PdfName key, PdfObject value)
Inserts the value into thePdfDictionary
of 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
public AbstractPdfFormField remove(PdfName key)
Removes the specified key from thePdfDictionary
of 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
public PdfDocument getDocument()
Gets thePdfDocument
that owns that form field.- Returns:
- the
PdfDocument
that 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:
isWrappedObjectMustBeIndirect
in classPdfObjectWrapper<PdfDictionary>
- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
setColor
public AbstractPdfFormField setColor(Color color)
Sets the text color and regenerates appearance stream.- Parameters:
color
- the new value for the Color.- Returns:
- the edited
AbstractPdfFormField
.
-
setFont
public AbstractPdfFormField setFont(PdfFont font)
Basic setter for thefont
property. 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
public AbstractPdfFormField setFontSize(float fontSize)
Basic setter for thefontSize
property. Regenerates the field appearance after setting the new value.- Parameters:
fontSize
- The new font size to be set.- Returns:
- The edited
AbstractPdfFormField
.
-
setFontSize
public AbstractPdfFormField setFontSize(int fontSize)
Basic setter for thefontSize
property. Regenerates the field appearance after setting the new value.- Parameters:
fontSize
- The new font size to be set.- Returns:
- The edited
AbstractPdfFormField
.
-
setFontSizeAutoScale
public 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
public AbstractPdfFormField setFontAndSize(PdfFont font, float fontSize)
Combined setter for thefont
andfontSize
properties. 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.
-
updateFontAndFontSize
void updateFontAndFontSize(PdfFont font, float fontSize)
-
retrieveStyles
void retrieveStyles()
-
splitDAelements
private static java.lang.Object[] splitDAelements(java.lang.String da)
-
resolveFontName
private PdfFont resolveFontName(java.lang.String fontName)
-
equals
public boolean equals(java.lang.Object o)
Indicate whether some other object is "equal to" this one. Compares wrapped objects.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Generate a hash code for this object.- Overrides:
hashCode
in classjava.lang.Object
-
-