# Widget Annotation

DsPdf is a Document Solutions product that offers a rich library to read, create, modify, and save PDF files without using any external tool.

## Content

Widget annotations are used in interactive forms to represent the appearance of fields. It is also used to manage user interaction. DsPdf provides [WidgetAnnotation](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Annotations.WidgetAnnotation.html) class to enable users to apply widget annotations to the PDF file.
![Widget annotation in a PDF file](https://cdn.mescius.io/document-site-files/images/884d2bfb-301b-49bc-8d90-656c5b910507/images/annotations/widget2.png)
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:

```csharp
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");
}
```