How to Add Comments to a PDF using C#

This article guides on how to add comments to a PDF using C#. You will get all the details to set the IDE, a list of steps to be performed, and a runnable sample code to add notes to PDF using C#. Details are shared to create text annotation along with setting its properties and a border and then adding it to the annotations collection of a particular page.

Steps to Insert Comment in PDF using C#

  1. Set the IDE to use Aspose.PDF for .NET to add comments
  2. Create a PDF using the Document class and some sample text on its first page
  3. Instantiate the TextAnnotation class object and initialize its properties
  4. Create a border for the annotation and link it with the text annotation object
  5. Add this text annotation to the collection of annotations on the selected page
  6. Save the resultant PDF file

The above steps describe the complete process to add comment in PDF using C#. In the first step, a TextAnnotation class object is created along with settings its properties like title, subject, state, contents, open flag, and Icon. In the final step, a border is created for the text annotation by settings its width and dash style and then added to the annotations collection of the selected page.

Code to Add Comments to PDF using C#

This code demonstrates the process of how to insert comment in PDF using C#. The TextAnnotation class is used by settings its few properties mentioned above however you may set other properties also like appearance, color, creation date, name, and opacity to name a very few. You can also set margins by setting the bottom, left, right, and top if required.

In this article, we have learned how to add comments in PDF file using C#. If you want to learn the process to add a header and footer, refer to the article on how to add header and footer in PDF using C#.

 English