In this how-to tutorial, you will learn the process to add reply to annotation in PDF using C#. This guide also contains the instructions to configure the annotation package to reply annotation in PDF using C#. You will easily learn how to add annotation into PDF and add replies to same annotation. Here are the detailed directions to create annotation replies into PDF along with sample code example.
Steps to Add Reply to Annotation in PDF using C#
- Install GroupDocs.Annotation for .NET package from the NuGet to reply PDF annotation
- Add reference to the GroupDocs.Annotation namespace to create annotation reply
- Instantiate Annotator object with input document path
- Instantiate User, AreaAnnotation, and Reply object(s)
- Assign User object to Reply
- Assign Reply object(s) to Replies collection of AreaAnnotation
- Call Annotator.Add method and pass annotation object to it
- Call Annotator.Save method with resultant document path
We have clarified all the essential steps to annotate PDF with reply in C# and save the resultant PDF to disk. You can start reply to annotation functionality by loading the input document using Annotator class, set annotation properties and finally save the resultant PDF to disk. Here is the code example to add replies to annotation.
Code to Add Reply to Annotation in PDF using C#
using GroupDocs.Annotation; | |
using GroupDocs.Annotation.Models; | |
using GroupDocs.Annotation.Models.AnnotationModels; | |
using System; | |
using System.Collections.Generic; | |
namespace AddReplytoAnnotationUsingCSharp | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Set License to avoid the limitations of Annotation library | |
License lic = new License(); | |
lic.SetLicense(@"Conholdate.Annotator.lic"); | |
// Instantiate Annotator object with input PDF path | |
using (Annotator annotator = new Annotator("input.pdf")) | |
{ | |
// Instantiate User objects | |
User user1 = new User | |
{ | |
Id = 1, | |
Name = "Tom", | |
Email = "somemail@mail.com" | |
}; | |
User user2 = new User | |
{ | |
Id = 2, | |
Name = "Jack", | |
Email = "somebody@mail.com" | |
}; | |
// Instantiate AreaAnnotation object and set its properties | |
AreaAnnotation area = new AreaAnnotation | |
{ | |
Box = new Rectangle(100, 100, 100, 100), | |
CreatedOn = DateTime.Now, | |
Message = "This is an area annotation", | |
PageNumber = 0, | |
Replies = new List<Reply> | |
{ | |
new Reply | |
{ | |
Id = 1, | |
Comment = "First comment", | |
RepliedOn = DateTime.Now, | |
User = user1 | |
}, | |
new Reply | |
{ | |
Id = 2, | |
Comment = "Second comment", | |
RepliedOn = DateTime.Now, | |
User = user2, | |
} | |
} | |
}; | |
//Add annotation into document | |
annotator.Add(area); | |
//Save the final output to disk | |
annotator.Save("AddReplytoAnnotationUsingCSharp.pdf"); | |
} | |
} | |
} | |
} |
The above code example presents the functionality to insert reply to PDF annotation in C# and completed it by consuming some API calls of annotation library. Moreover, this C# code example can be executed on any common operating system that supports .NET like MS Windows, Linux, and Mac OS. Recently, we published an article on adding watermark in Word, have a look at how to add watermark in Word using C# guide for more information.