Add text field annotation

On this page

Text field annotation adds a rectangle with a text inside as shown in the picture below:

You can specify the following properties of the TextFieldAnnotation class:

  • BackgroundColor defines the area background color
  • Box defines the annotation position at the document page
  • Text defines the text to place in the rectangle
  • FontColor defines the color of the text
  • FontFamily defines the name of the text font
  • FontSize defines the size of the text font
  • Opacity allows you to set the annotation opacity
  • PenStyle defines the frame line style (solid, dash, dot etc.)
  • PenWidth - defines frame line width in pixels
  • PenColor defines the frame color
  • TextHorizontalAlignment defines the text horizontal alignment

To add a text field annotation, follow these steps: 

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the TextFieldAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the TextFieldAnnotation class.
  4. Call the Save method. Specify the output document path or stream.

The following code snippet shows how to add TextFieldAnnotation to the document:

//Add text field annotation to the document from local disk
using (Annotator annotator = new Annotator("input.pdf"))
{
	TextFieldAnnotation textField = new TextFieldAnnotation
    {
    	BackgroundColor = 65535,
        Box = new Rectangle(100, 100, 100, 100),
        CreatedOn = DateTime.Now,
        Text = "Some text",
        FontColor = 65535,
        FontSize = 12,
        Message = "This is text field annotation",
        Opacity = 0.7,
        PageNumber = 0,
        PenStyle = PenStyle.Dot,
        PenWidth = 3,
        FontFamily = "Arial",
        TextHorizontalAlignment = HorizontalAlignment.Center,
        Replies = new List<Reply>
        {
        	new Reply
            {
            	Comment = "First comment",
                RepliedOn = DateTime.Now
            },
            new Reply
            {
            	Comment = "Second comment",
                RepliedOn = DateTime.Now
            }
        }
	};
    annotator.Add(textField);
    annotator.Save("result.pdf");
} 

On this page