Table of Contents

Class PdfFormAnnotation

Namespace
iText.Forms.Fields
Assembly
itext.forms.dll

This class represents a single annotation in form fields hierarchy in an AcroForm.

public class PdfFormAnnotation : AbstractPdfFormField
Inheritance
PdfFormAnnotation
Inherited Members

Remarks

This class represents a single annotation in form fields hierarchy in an AcroForm.

To be able to be wrapped with this PdfObjectWrapper<T> the PdfObject must be indirect.

Constructors

PdfFormAnnotation(PdfWidgetAnnotation, PdfDocument)

Creates a form field annotation as a wrapper of a PdfWidgetAnnotation.

protected PdfFormAnnotation(PdfWidgetAnnotation widget, PdfDocument pdfDocument)

Parameters

widget PdfWidgetAnnotation

The widget which will be a kid of the PdfFormField

pdfDocument PdfDocument

The PdfDocument instance.

PdfFormAnnotation(PdfDictionary)

Creates a form field annotation as a wrapper object around a PdfDictionary.

protected PdfFormAnnotation(PdfDictionary pdfObject)

Parameters

pdfObject PdfDictionary

the dictionary to be wrapped, must have an indirect reference.

Remarks

Creates a form field annotation as a wrapper object around a PdfDictionary. This PdfDictionary must be an indirect object.

Fields

HIDDEN

public const int HIDDEN = 1

Field Value

int

HIDDEN_BUT_PRINTABLE

public const int HIDDEN_BUT_PRINTABLE = 3

Field Value

int

OFF_STATE_VALUE

Value which represents "off" state of form field.

public const string OFF_STATE_VALUE = "Off"

Field Value

string

ON_STATE_VALUE

Value which represents "on" state of form field.

public const string ON_STATE_VALUE = "Yes"

Field Value

string

VISIBLE

public const int VISIBLE = 4

Field Value

int

VISIBLE_BUT_DOES_NOT_PRINT

public const int VISIBLE_BUT_DOES_NOT_PRINT = 2

Field Value

int

backgroundColor

protected Color backgroundColor

Field Value

Color

borderColor

protected Color borderColor

Field Value

Color

borderWidth

protected float borderWidth

Field Value

float

Methods

DrawBorder(PdfCanvas, PdfFormXObject, float, float)

Draws a border using the borderWidth and borderColor of the form field.

protected virtual void DrawBorder(PdfCanvas canvas, PdfFormXObject xObject, float width, float height)

Parameters

canvas PdfCanvas

The PdfCanvas on which to draw

xObject PdfFormXObject

The PdfFormXObject

width float

The width of the rectangle to draw

height float

The height of the rectangle to draw

DrawCheckBoxAndSaveAppearance(string)

Draw a checkbox and save its appearance.

protected virtual void DrawCheckBoxAndSaveAppearance(string onStateName)

Parameters

onStateName string

the name of the appearance state for the checked state

DrawComboBoxAndSaveAppearance()

Draws the appearance of a Combo box form field and saves it into an appearance stream.

protected virtual void DrawComboBoxAndSaveAppearance()

DrawListFormFieldAndSaveAppearance()

Draws the appearance of a list box form field and saves it into an appearance stream.

protected virtual void DrawListFormFieldAndSaveAppearance()

DrawPushButtonFieldAndSaveAppearance()

Draws the appearance of a push button and saves it into an appearance stream.

protected virtual void DrawPushButtonFieldAndSaveAppearance()

DrawRadioButtonAndSaveAppearance(string)

Draws the appearance of a radio button with a specified value and saves it into an appearance stream.

protected virtual void DrawRadioButtonAndSaveAppearance(string value)

Parameters

value string

the value of the radio button.

DrawSignatureFormFieldAndSaveAppearance()

Draws the appearance of a signature field and saves it into an appearance stream.

protected virtual void DrawSignatureFormFieldAndSaveAppearance()

DrawTextFormFieldAndSaveAppearance()

Draws the appearance of a text form field and saves it into an appearance stream.

protected virtual void DrawTextFormFieldAndSaveAppearance()

GetAppearanceStates()

Gets the appearance state names.

public override string[] GetAppearanceStates()

Returns

string[]

an array of Strings containing the names of the appearance states.

GetBorder()

Get border object specified in the widget annotation dictionary.

public virtual Border GetBorder()

Returns

Border

Border specified in the widget annotation dictionary

GetBorderWidth()

Gets the border width for the field.

public virtual float GetBorderWidth()

Returns

float

the current border width.

GetDefaultAppearance()

public override PdfString GetDefaultAppearance()

Returns

PdfString

GetRect(PdfDictionary)

Gets a Rectangle that matches the current size and position of this form field.

protected virtual Rectangle GetRect(PdfDictionary field)

Parameters

field PdfDictionary

current form field.

Returns

Rectangle

a Rectangle that matches the current size and position of this form field annotation.

GetRotation()

Get rotation property specified in this form annotation.

public virtual int GetRotation()

Returns

int

int value which represents field's rotation

GetWidget()

Gets PdfWidgetAnnotation that this form field refers to.

public virtual PdfWidgetAnnotation GetWidget()

Returns

PdfWidgetAnnotation

PdfWidgetAnnotation.

MakeFormAnnotation(PdfObject, PdfDocument)

Creates a PdfFormAnnotation object.

public static PdfFormAnnotation MakeFormAnnotation(PdfObject pdfObject, PdfDocument document)

Parameters

pdfObject PdfObject

assumed to be either a PdfDictionary , or a PdfIndirectReference to a PdfDictionary.

document PdfDocument

the PdfDocument to create the field in.

Returns

PdfFormAnnotation

a new PdfFormAnnotation , or null if pdfObject is not a widget annotation.

RegenerateField()

public override bool RegenerateField()

Returns

bool

SetAction(PdfAction)

Sets the action on widget of this annotation form field.

public virtual PdfFormAnnotation SetAction(PdfAction action)

Parameters

action PdfAction

The action.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetAppearance(PdfName, string, PdfStream)

Sets an appearance for (the widgets related to) the form field.

public virtual PdfFormAnnotation SetAppearance(PdfName appearanceType, string appearanceState, PdfStream appearanceStream)

Parameters

appearanceType PdfName

the type of appearance stream to be added

  • PdfName.N: normal appearance
  • PdfName.R: rollover appearance
  • PdfName.D: down appearance
appearanceState string

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 PdfStream

the appearance instructions, as a PdfStream.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetBackgroundColor(Color)

Basic setter for the backgroundColor property.

public virtual PdfFormAnnotation SetBackgroundColor(Color backgroundColor)

Parameters

backgroundColor Color

The new color to be set or null if no background needed.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

Remarks

Basic setter for the backgroundColor property. Regenerates the field appearance after setting the new value.

SetBorderColor(Color)

Sets the Border Color.

public virtual PdfFormAnnotation SetBorderColor(Color color)

Parameters

color Color

the new value for the Border Color.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetBorderStyle(PdfDictionary)

Sets the border style for the field.

public virtual PdfFormAnnotation SetBorderStyle(PdfDictionary style)

Parameters

style PdfDictionary

the new border style.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetBorderWidth(float)

Sets the border width for the field.

public virtual PdfFormAnnotation SetBorderWidth(float borderWidth)

Parameters

borderWidth float

The new border width.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetCaption(string)

Basic setter for the push button caption.

public virtual PdfFormAnnotation SetCaption(string caption)

Parameters

caption string

button caption to be set.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

Remarks

Basic setter for the push button caption. Regenerates the field appearance after setting the new caption.

SetCaption(string, bool)

Basic setter for the push button caption.

public virtual PdfFormAnnotation SetCaption(string caption, bool regenerateField)

Parameters

caption string

button caption to be set.

regenerateField bool

true if field should be regenerated, false otherwise.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

Remarks

Basic setter for the push button caption. Regenerates the field appearance after setting the new caption if corresponding parameter is specified.

SetCheckBoxAppearanceOnStateName(string)

Sets on state name for the checkbox annotation normal appearance and regenerates widget.

public virtual PdfFormAnnotation SetCheckBoxAppearanceOnStateName(string onStateName)

Parameters

onStateName string

the new appearance name representing on state.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetFormFieldElement(IFormField)

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.

public virtual PdfFormAnnotation SetFormFieldElement(IFormField element)

Parameters

element IFormField

model element to set.

Returns

PdfFormAnnotation

this PdfFormAnnotation.

Remarks

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.

SetPage(int)

Specifies on which page the form field's widget must be shown.

public virtual PdfFormAnnotation SetPage(int pageNum)

Parameters

pageNum int

the page number.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

SetRotation(int)

Basic setter for the degRotation property.

public virtual PdfFormAnnotation SetRotation(int degRotation)

Parameters

degRotation int

The new degRotation to be set

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

Remarks

Basic setter for the degRotation property. Regenerates the field appearance after setting the new value.

SetVisibility(int)

Set the visibility flags of the form field annotation.

public virtual PdfFormAnnotation SetVisibility(int visibility)

Parameters

visibility int

visibility option.

Returns

PdfFormAnnotation

The edited PdfFormAnnotation.

Remarks

Set the visibility flags of the form field annotation. Options are: HIDDEN, HIDDEN_BUT_PRINTABLE, VISIBLE, VISIBLE_BUT_DOES_NOT_PRINT.