Table of Contents

Class PushbuttonField

Namespace
iTextSharp.text.pdf
Assembly
iTextSharp.LGPLv2.Core.dll

Creates a pushbutton field. It supports all the text and icon alignments. The icon may be an image or a template. Example usage: Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.GetInstance(document, new FileOutputStream("output.pdf")); document.Open(); PdfContentByte cb = writer.GetDirectContent(); Image img = Image.GetInstance("image.png"); PushbuttonField bt = new PushbuttonField(writer, new Rectangle(100, 100, 200, 200), "Button1"); bt.SetText("My Caption"); bt.SetFontSize(0); bt.SetImage(img); bt.SetLayout(PushbuttonField.LAYOUT_ICON_TOP_LABEL_BOTTOM); bt.SetBackgroundColor(Color.cyan); bt.SetBorderStyle(PdfBorderDictionary.STYLE_SOLID); bt.SetBorderColor(Color.red); bt.SetBorderWidth(3); PdfFormField ff = bt.GetField(); PdfAction ac = PdfAction.CreateSubmitForm("http://www.submit-site.com", null, 0); ff.SetAction(ac); writer.AddAnnotation(ff); document.Close(); @author Paulo Soares (psoares@consiste.pt)

public class PushbuttonField : BaseField
Inheritance
PushbuttonField
Inherited Members

Constructors

PushbuttonField(PdfWriter, Rectangle, string)

Creates a new instance of PushbuttonField will be included in the field allowing it to be used as a kid field.

public PushbuttonField(PdfWriter writer, Rectangle box, string fieldName)

Parameters

writer PdfWriter

the document PdfWriter

box Rectangle

the field location and dimensions

fieldName string

the field name. If null only the widget keys

Fields

LAYOUT_ICON_LEFT_LABEL_RIGHT

A layout option

public const int LAYOUT_ICON_LEFT_LABEL_RIGHT = 5

Field Value

int

LAYOUT_ICON_ONLY

A layout option

public const int LAYOUT_ICON_ONLY = 2

Field Value

int

LAYOUT_ICON_TOP_LABEL_BOTTOM

A layout option

public const int LAYOUT_ICON_TOP_LABEL_BOTTOM = 3

Field Value

int

LAYOUT_LABEL_LEFT_ICON_RIGHT

A layout option

public const int LAYOUT_LABEL_LEFT_ICON_RIGHT = 6

Field Value

int

LAYOUT_LABEL_ONLY

A layout option

public const int LAYOUT_LABEL_ONLY = 1

Field Value

int

LAYOUT_LABEL_OVER_ICON

A layout option

public const int LAYOUT_LABEL_OVER_ICON = 7

Field Value

int

LAYOUT_LABEL_TOP_ICON_BOTTOM

A layout option

public const int LAYOUT_LABEL_TOP_ICON_BOTTOM = 4

Field Value

int

SCALE_ICON_ALWAYS

An icon scaling option

public const int SCALE_ICON_ALWAYS = 1

Field Value

int

SCALE_ICON_IS_TOO_BIG

An icon scaling option

public const int SCALE_ICON_IS_TOO_BIG = 3

Field Value

int

SCALE_ICON_IS_TOO_SMALL

An icon scaling option

public const int SCALE_ICON_IS_TOO_SMALL = 4

Field Value

int

SCALE_ICON_NEVER

An icon scaling option

public const int SCALE_ICON_NEVER = 2

Field Value

int

Properties

Field

Gets the pushbutton field. @throws IOException on error @throws DocumentException on error

public PdfFormField Field { get; }

Property Value

PdfFormField

the pushbutton field

IconFitToBounds

If true the icon will be scaled to fit fully within the bounds of the annotation, if false the border width will be taken into account. The default is false . if false the border width will be taken into account

public bool IconFitToBounds { get; set; }

Property Value

bool

IconHorizontalAdjustment

A number between 0 and 1 indicating the fraction of leftover space to allocate at the left of the icon. A value of 0 positions the icon at the left of the annotation rectangle. A value of 0.5 centers it within the rectangle. The default is 0.5.

public float IconHorizontalAdjustment { get; set; }

Property Value

float

IconReference

Sets the reference to an existing icon.

public PrIndirectReference IconReference { get; set; }

Property Value

PrIndirectReference

IconVerticalAdjustment

A number between 0 and 1 indicating the fraction of leftover space to allocate at the bottom of the icon. A value of 0 positions the icon at the bottom of the annotation rectangle. A value of 0.5 centers it within the rectangle. The default is 0.5.

public float IconVerticalAdjustment { get; set; }

Property Value

float

Image

Sets the icon as an image.

public Image Image { get; set; }

Property Value

Image

Layout

Sets the icon and label layout. Possible values are LAYOUT_LABEL_ONLY , LAYOUT_ICON_ONLY , LAYOUT_ICON_TOP_LABEL_BOTTOM , LAYOUT_LABEL_TOP_ICON_BOTTOM , LAYOUT_ICON_LEFT_LABEL_RIGHT , LAYOUT_LABEL_LEFT_ICON_RIGHT and LAYOUT_LABEL_OVER_ICON . The default is LAYOUT_LABEL_ONLY .

public int Layout { get; set; }

Property Value

int

ProportionalIcon

Sets the way the icon is scaled. If true the icon is scaled proportionally, if false the scaling is done anamorphicaly.

public bool ProportionalIcon { get; set; }

Property Value

bool

ScaleIcon

Sets the way the icon will be scaled. Possible values are SCALE_ICON_ALWAYS , SCALE_ICON_NEVER , SCALE_ICON_IS_TOO_BIG and SCALE_ICON_IS_TOO_SMALL . The default is SCALE_ICON_ALWAYS .

public int ScaleIcon { get; set; }

Property Value

int

Template

Sets the icon as a template.

public PdfTemplate Template { get; set; }

Property Value

PdfTemplate

Methods

GetAppearance()

Gets the button appearance. @throws IOException on error @throws DocumentException on error

public PdfAppearance GetAppearance()

Returns

PdfAppearance

the button appearance