[]
Widget annotations are used in interactive forms to represent the appearance of fields. It is also used to manage user interaction. GcPdf provides WidgetAnnotation class to enable users to apply widget annotations to the PDF file.
WidgetAnnotation class provides the following properties to set various options for the widget annotation:
Property | Description |
---|---|
Border | Sets various properties of border such as color, pattern, style, and width. |
BackColor | Sets the annotation's background color. |
RotationAngle | Sets the angle, in degrees, by which the widget annotation is rotated counterclockwise relative to the page. The value must be a multiple of 90. |
PdfRect | Sets the rectangle that defines the location and size of the annotation on a page in PDF user space coordinates. The positive X axis extends horizontally to the right, and the positive Y axis extends vertically upward, with the origin usually in the lower left corner of the page. |
Refer to the following example code to add a widget annotation to a PDF document:
public void CreateWidgetAnnotation()
{
var doc = new GcPdfDocument();
var page = doc.NewPage();
var g = page.Graphics;
TextFormat tf = new TextFormat();
tf.FontSize = 11;
PointF ip = new PointF(72, 72);
float fldOffset = 72 * 2;
float fldHeight = tf.FontSize * 1.2f;
float dY = 32;
// Text field:
g.DrawString("Text field:", tf, ip);
var fldText = new TextField();
fldText.Value = "Initial TextField value";
//Get the WidgetAnnotation to specify view properties of the text field.
WidgetAnnotation widgetAnnotation = fldText.Widget;
widgetAnnotation.Page = page;
widgetAnnotation.PdfRect = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
widgetAnnotation.Border.Color = Color.Silver;
widgetAnnotation.BackColor = Color.LightSkyBlue;
doc.AcroForm.Fields.Add(fldText);
ip.Y += dY;
doc.Save("WidgetAnnotation.pdf");
}