Package com.itextpdf.forms.fields
Class PdfFormAnnotation
java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
com.itextpdf.forms.fields.AbstractPdfFormField
com.itextpdf.forms.fields.PdfFormAnnotation
This class represents a single annotation in form fields hierarchy in an
AcroForm.
To be able to be wrapped with this PdfObjectWrapper the PdfObject must be indirect.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Colorprotected Colorprotected floatstatic final intstatic final intstatic final StringValue which represents "off" state of form field.static final StringValue which represents "on" state of form field.static final intstatic final intFields inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
color, DEFAULT_FONT_SIZE, font, fontSize, MIN_FONT_SIZE, parent, pdfConformance -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPdfFormAnnotation(PdfWidgetAnnotation widget, PdfDocument pdfDocument) Creates a form field annotation as a wrapper of aPdfWidgetAnnotation.protectedPdfFormAnnotation(PdfDictionary pdfObject) Creates a form field annotation as a wrapper object around aPdfDictionary. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddrawBorder(PdfCanvas canvas, PdfFormXObject xObject, float width, float height) Draws a border using the borderWidth and borderColor of the form field.protected voiddrawCheckBoxAndSaveAppearance(String onStateName) Draw a checkbox and save its appearance.protected voidDraws the appearance of a Combo box form field and saves it into an appearance stream.protected voidDraws the appearance of a list box form field and saves it into an appearance stream.protected voidDraws the appearance of a push button and saves it into an appearance stream.protected voidDraws the appearance of a radio button with a specified value and saves it into an appearance stream.protected voidDraws the appearance of a signature field and saves it into an appearance stream.protected voidDraws the appearance of a text form field and saves it into an appearance stream.Gets the current alternative description.String[]Gets the appearance state names.Get border object specified in the widget annotation dictionary.floatGets the border width for the field.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.protected RectanglegetRect(PdfDictionary field) Gets aRectanglethat matches the current size and position of this form field.intGet rotation property specified in this form annotation.GetsPdfWidgetAnnotationthat this form field refers to.static PdfFormAnnotationmakeFormAnnotation(PdfObject pdfObject, PdfDocument document) Creates aPdfFormAnnotationobject.booleanThis method regenerates appearance stream of the field.Sets the action onwidgetof this annotation form field.setAlternativeDescription(String alternativeDescription) Changes the alternative description of the annotation to the specified value.setAppearance(PdfName appearanceType, String appearanceState, PdfStream appearanceStream) Sets an appearance for (the widgets related to) the form field.setBackgroundColor(Color backgroundColor) Basic setter for thebackgroundColorproperty.setBorderColor(Color color) Sets the Border Color.setBorderStyle(PdfDictionary style) Sets the border style for the field.setBorderWidth(float borderWidth) Sets the border width for the field.setCaption(String caption) Basic setter for the push button caption.setCaption(String caption, boolean regenerateField) Basic setter for the push button caption.setCheckBoxAppearanceOnStateName(String onStateName) Sets on state name for the checkbox annotation normal appearance and regenerates widget.setFormFieldElement(IFormField element) This method sets the model element associated with the current annotation and can be useful to take into account when drawing those properties that the annotation does not have.setPage(int pageNum) Specifies on which page the form field's widget must be shown.setRotation(int degRotation) Basic setter for thedegRotationproperty.setVisibility(int visibility) Set the visibility flags of the form field annotation.Methods inherited from class com.itextpdf.forms.fields.AbstractPdfFormField
disableCurrentFieldRegeneration, disableFieldRegeneration, enableCurrentFieldRegeneration, enableFieldRegeneration, equals, getColor, getDocument, getFieldName, getFont, getFontSize, getParent, getParentField, getPdfConformance, getPdfObject, hashCode, isFieldRegenerationEnabled, isTerminalFormField, isWrappedObjectMustBeIndirect, put, release, remove, setColor, setFont, setFontAndSize, setFontSize, setFontSize, setFontSizeAutoScale, setParentMethods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
Field Details
-
HIDDEN
public static final int HIDDEN- See Also:
-
VISIBLE_BUT_DOES_NOT_PRINT
public static final int VISIBLE_BUT_DOES_NOT_PRINT- See Also:
-
HIDDEN_BUT_PRINTABLE
public static final int HIDDEN_BUT_PRINTABLE- See Also:
-
VISIBLE
public static final int VISIBLE- See Also:
-
OFF_STATE_VALUE
Value which represents "off" state of form field.- See Also:
-
ON_STATE_VALUE
Value which represents "on" state of form field.- See Also:
-
borderWidth
protected float borderWidth -
backgroundColor
-
borderColor
-
-
Constructor Details
-
PdfFormAnnotation
Creates a form field annotation as a wrapper of aPdfWidgetAnnotation.- Parameters:
-
widget- The widget which will be a kid of thePdfFormField -
pdfDocument- ThePdfDocumentinstance.
-
PdfFormAnnotation
Creates a form field annotation 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
-
makeFormAnnotation
Creates aPdfFormAnnotationobject.- Parameters:
-
pdfObject- assumed to be either aPdfDictionary, or aPdfIndirectReferenceto aPdfDictionary. -
document- thePdfDocumentto create the field in. - Returns:
-
a new
PdfFormAnnotation, ornullifpdfObjectis not a widget annotation.
-
getWidget
GetsPdfWidgetAnnotationthat this form field refers to.- Returns:
-
PdfWidgetAnnotation.
-
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.
-
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.
-
getAppearanceStates
Gets the appearance state names.- Specified by:
-
getAppearanceStatesin classAbstractPdfFormField - Returns:
- an array of Strings containing the names of the appearance states.
-
setBackgroundColor
Basic setter for thebackgroundColorproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
backgroundColor- The new color to be set ornullif no background needed. - Returns:
-
The edited
PdfFormAnnotation.
-
setCaption
Basic setter for the push button caption. Regenerates the field appearance after setting the new caption.- Parameters:
-
caption- button caption to be set. - Returns:
-
The edited
PdfFormAnnotation.
-
setCaption
Basic setter for the push button caption. Regenerates the field appearance after setting the new caption if corresponding parameter is specified.- Parameters:
-
caption- button caption to be set. -
regenerateField- true if field should be regenerated, false otherwise. - Returns:
-
The edited
PdfFormAnnotation.
-
getRotation
public int getRotation()Get rotation property specified in this form annotation.- Returns:
-
intvalue which represents field's rotation
-
setRotation
Basic setter for thedegRotationproperty. Regenerates the field appearance after setting the new value.- Parameters:
-
degRotation- The new degRotation to be set - Returns:
-
The edited
PdfFormAnnotation.
-
setAction
Sets the action onwidgetof this annotation form field.- Parameters:
-
action- The action. - Returns:
-
The edited
PdfFormAnnotation.
-
setVisibility
Set the visibility flags of the form field annotation. Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT.- Parameters:
-
visibility- visibility option. - Returns:
-
The edited
PdfFormAnnotation.
-
getBorderWidth
public float getBorderWidth()Gets the border width for the field.- Returns:
- the current border width.
-
setBorderWidth
Sets the border width for the field.- Parameters:
-
borderWidth- The new border width. - Returns:
-
The edited
PdfFormAnnotation.
-
getBorder
Get border object specified in the widget annotation dictionary.- Returns:
-
Borderspecified in the widget annotation dictionary
-
setBorderStyle
Sets the border style for the field.- Parameters:
-
style- the new border style. - Returns:
-
The edited
PdfFormAnnotation.
-
setBorderColor
Sets the Border Color.- Parameters:
-
color- the new value for the Border Color. - Returns:
-
The edited
PdfFormAnnotation.
-
setPage
Specifies on which page the form field's widget must be shown.- Parameters:
-
pageNum- the page number. - Returns:
-
The edited
PdfFormAnnotation.
-
setFormFieldElement
This method sets the model element associated with the current annotation and can be useful to take into account when drawing those properties that the annotation does not have. Note that annotation properties will take precedence, so such properties cannot be overridden by using this method (e.g. background, text color, etc.).Also note that the model element won't be used for annotations for choice form field.
- Parameters:
-
element- model element to set - Returns:
-
this
PdfFormAnnotation
-
setAppearance
public PdfFormAnnotation setAppearance(PdfName appearanceType, String appearanceState, PdfStream appearanceStream) Sets an appearance for (the widgets related to) the form field.- Parameters:
-
appearanceType- the type of appearance stream to be added- PdfName.N: normal appearance
- PdfName.R: rollover appearance
- PdfName.D: down appearance
-
appearanceState- the state of the form field that needs to be true for the appearance to be used. Differentiates between several streams of the same type. -
appearanceStream- the appearance instructions, as aPdfStream. - Returns:
-
The edited
PdfFormAnnotation.
-
setCheckBoxAppearanceOnStateName
Sets on state name for the checkbox annotation normal appearance and regenerates widget.- Parameters:
-
onStateName- the new appearance name representing on state. - Returns:
-
The edited
PdfFormAnnotation.
-
setAlternativeDescription
Changes the alternative description of the annotation to the specified value.- Parameters:
-
alternativeDescription- string to be used as alternative description. - Returns:
-
The edited
PdfFormAnnotation.
-
getAlternativeDescription
Gets the current alternative description.- Returns:
- the current alternative description.
-
getRect
Gets aRectanglethat matches the current size and position of this form field.- Parameters:
-
field- current form field. - Returns:
-
a
Rectanglethat matches the current size and position of this form field annotation.
-
drawBorder
Draws a border using the borderWidth and borderColor of the form field.- Parameters:
-
canvas- ThePdfCanvason which to draw -
xObject- The PdfFormXObject -
width- The width of the rectangle to draw -
height- The height of the rectangle to draw
-
drawPushButtonFieldAndSaveAppearance
protected void drawPushButtonFieldAndSaveAppearance()Draws the appearance of a push button and saves it into an appearance stream. -
drawSignatureFormFieldAndSaveAppearance
protected void drawSignatureFormFieldAndSaveAppearance()Draws the appearance of a signature field and saves it into an appearance stream. -
drawRadioButtonAndSaveAppearance
Draws the appearance of a radio button with a specified value and saves it into an appearance stream.- Parameters:
-
value- the value of the radio button.
-
drawListFormFieldAndSaveAppearance
protected void drawListFormFieldAndSaveAppearance()Draws the appearance of a list box form field and saves it into an appearance stream. -
drawTextFormFieldAndSaveAppearance
protected void drawTextFormFieldAndSaveAppearance()Draws the appearance of a text form field and saves it into an appearance stream. -
drawComboBoxAndSaveAppearance
protected void drawComboBoxAndSaveAppearance()Draws the appearance of a Combo box form field and saves it into an appearance stream. -
drawCheckBoxAndSaveAppearance
Draw a checkbox and save its appearance.- Parameters:
-
onStateName- the name of the appearance state for the checked state
-