How to Add Special Annotations for PDF using .NET

Special annotations for PDF documents only

We think it’s no secret that the PDF format is the most popular format among text documents. Many people prefer to use it because they know that the style and formatting of the document is maintained regardless of the computer or application with which the PDF is viewed. Given its popularity, our .NET API has been improved. We have created annotations unique to the PDF format, the so-called Components. As you know, our .NET API supports a large number of annotations that can be applied to different documents - Word documents, Excel sheets, Visio diagrams, PDF etc. But Component support PDF only!

This article will talk about the components that are already implemented in the Annotation .NET API and how you can use them.

Button component

Button component allows to create button component like shown at the picture below:

There is an ability to specify the next properties for ButtonComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;

Follow these steps to add Button component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate ButtonComponent object with desired properties (position, page number, etc);
  • Call Add method and pass ButtonComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add ButtonComponent to the document:

using (Annotator annotator = new Annotator("input.pdf"))
{
	ButtonComponent button = new ButtonComponent
    {
        CreatedOn = DateTime.Now,
        Style = BorderStyle.Dashed,
        Message = "This is button component",
        BorderColor = 1422623,
        PenColor = 14527697,
        ButtonColor = 10832612,
        PageNumber = 0,
        BorderWidth = 12,
        Box = new Rectangle(100, 300, 90, 30),
        Replies = new List<Reply>
            {
                new Reply
                {
                    Comment = "First comment",
                    RepliedOn = DateTime.Now
                },
                new Reply
                {
                    Comment = "Second comment",
                    RepliedOn = DateTime.Now
                }
            }
    };
    annotator.Add(button);
    annotator.Save("result.pdf");
}

Checkbox component

Checkbox component allows to create checkbox component like shown at the picture below:

There is an ability to specify the next properties for CheckBoxComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;

Follow these steps to add Checkbox component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate CheckboxComponent object with desired properties (position, page number, etc);
  • Call Add method and pass CheckboxComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add CheckboxComponent to the document:

using (Annotator annotator = new Annotator("input.pdf"))
{
	CheckBoxComponent checkbox = new CheckBoxComponent
    {
        Checked = true,
        Box = new Rectangle(100, 100, 100, 100),
        PenColor = 65535,
        Style = BoxStyle.Star,
        Replies = new List<Reply>
            {
                new Reply
                {
                    Comment = "First comment",
                    RepliedOn = DateTime.Now
                },
                new Reply
                {
                    Comment = "Second comment",
                    RepliedOn = DateTime.Now
                }
            }
    };
    annotator.Add(checkbox);
    annotator.Save("result.pdf");
}

Dropdown component allows to create combo box with specified options like shown at the picture below:

There is an ability to specify the next properties for DropdownComponent type:

  • Box - defines annotation position at document page;
  • PenColor - defines frame color;
  • PenStyle - defines frame line style (solid, dash, dot etc.);
  • PenWidth - defines frame line width in pixels.

Follow these steps to add Dropdown component to document:

  • Instantiate Annotator object with input document path or stream;
  • Instantiate DropdownComponent object with desired properties (position, page number, etc);
  • Call Add method and pass DropdownComponent object;
  • Call Save method with resultant document path or stream.

The following code demonstrates how to add DropdownComponent to the document:

using (Annotator annotator = new Annotator("input.pdf"))
{
	DropdownComponent dropdown = new DropdownComponent
    {
        Options = new List<string> { "Item1", "Item2", "Item3" },
        SelectedOption = null,
        Placeholder = "Choose option",
        Box = new Rectangle(100, 100, 100, 100),
        CreatedOn = DateTime.Now,
        Message = "This is dropdown component",
        PageNumber = 0,
        PenColor = 65535,
        PenStyle = PenStyle.Dot,
        PenWidth = 3,
        Replies = new List<Reply>
        {
            new Reply
            {
                Comment = "First comment",
                RepliedOn = DateTime.Now
            },
            new Reply
            {
                Comment = "Second comment",
                RepliedOn = DateTime.Now
            }
        }
    };
    annotator.Add(dropdown);
    annotator.Save("result.pdf");
}

Conclusion

In this article we have told you about components that are unique to pdf. We showed you how to add a button, a checkbox and a drop-down list. Now, you should be confident to build your own document annotator using our .NET application API.

More resources

Advanced Usage Topics

To learn more about document annotating features, please refer to the advanced usage section.

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to annotate your PDF, DOC or DOCX, XLS or XLSX, PPT or PPTX, PNG and other documents with free to use online GroupDocs Annotation App.

© Aspose Pty Ltd 2001-2022. All Rights Reserved.