How to Add or Remove Annotations from PDF files using .NET
How to Add or Remove Annotations from PDF files using .NET
Leave feedback
On this page
There was a time when we used to discuss document content and feedback in long email threads with multiple attachments and different file versions. Now we can simply use annotations to markup the document with messages and replies and send it. In this article, you will learn how to programmatically annotate PDF documents in .NET with your application. Additionally, we will see how to remove annotations from PDF files using the same .NET API.
PDF Annotator .NET API
To deal with annotations of your document and images within your .NET applications, GroupDocs provides GroupDocs.Annotation for .NET. Using the API, you can add, remove, and extract annotations from word-processing documents, spreadsheets, presentations, images, email messages, Visio drawings, some AutoCAD, and digital imaging formats like DICOM. Furthermore, the API allows annotating PDF files. You may have a look at the documentation to know about the long list of supported document formats for annotation.
Download and Configure
Get the annotation library using NuGet Package Manager in your .NET applications to try the examples of this article. To always stay up to date, make sure you are using latest version of the product. You can find many more example available on GitHub. For the details, you may visit the API Reference.
Let’s quickly jump to add some of the different kinds of annotations to the PDF document. As there are many different types of annotation, we may not cover all in this article. I will just mention them, and you may learn about each annotation individually.
Area / Rectangle annotation
Arrow
Distance
Ellipse
Highlight
Link
Point
Polyline
Replacement
Resource Redaction
Strikeout
Text Field
Text Redaction
Underline
Watermark
Let’s start adding some of these in a PDF document.
Add Arrow Annotation to PDF using .NET
The following are the steps to add arrow annotation to a PDF document.
Set the position and size of the arrow using Box property of ArrowAnnotation.
Add the created arrow annotation to the Annotator object.
Save the annotated PDF by providing the path using the Save method.
The following code sample shows how to add arrow annotation to a PDF document using .NET.
using(Annotatorannotator=newAnnotator("input.pdf")){ArrowAnnotationarrow=newArrowAnnotation{Box=newRectangle(100,100,100,100),CreatedOn=DateTime.Now,Message="This is arrow annotation",Opacity=0.7,PageNumber=0,PenColor=65535,PenStyle=PenStyle.Dot,PenWidth=3,Replies=newList<Reply>{newReply{Comment="First comment",RepliedOn=DateTime.Now},newReply{Comment="Second comment",RepliedOn=DateTime.Now}}};annotator.Add(arrow);annotator.Save("result.pdf");}
Insert Rectangle or Area Annotation to PDF using .NET
You can customize any annotation while adding it to the document. The following are the steps to add rectangle or area annotation to a PDF document with little more customizations. It is similar to adding Arrow annotation but uses AreaAnnotation class in place of ArrowAnnotation.
Initialize rectangle annotation using AreaAnnotation class.
Set the position and size of the rectangle using Box property of AreaAnnotation.
Set other properties like PenColor, BackgroundColor, Opacity, PenStyle, PenWidth, and even Replies.
Add the created rectangle annotation to the Annotator object.
Save the annotated PDF by providing the path using the Save method.
The following code sample shows how to add rectangle/area annotation to a PDF document using .NET.
using(Annotatorannotator=newAnnotator("input.pdf")){AreaAnnotationarea=newAreaAnnotation{BackgroundColor=65535,Box=newRectangle(100,100,100,100),CreatedOn=DateTime.Now,Message="This is area annotation",Opacity=0.7,PageNumber=0,PenColor=65535,PenStyle=PenStyle.Dot,PenWidth=3,Replies=newList<Reply>{newReply{Comment="First comment",RepliedOn=DateTime.Now},newReply{Comment="Second comment",RepliedOn=DateTime.Now}}};annotator.Add(area);annotator.Save("result.pdf");}
We have only shown you 2 examples because all the other types of annotation work in a similar way. You can try and add all the other annotations yourself or by following our detailed guides related to every annotation we support.
Remove Annotations from PDF in .NET
The following steps show how to remove all the annotations from PDF files in .NET.
In short, you have learned how to add annotations to PDF within .NET applications. Further, you have seen how to remove all the annotations from any PDF file. Now, you should be confident to build your own document annotator .NET application. It can support different types of annotations using GroupDocs.Annotation for .NET.
For more details, options, and examples, you can visit the documentation and the GitHub repository. For further queries, contact the support on the forum.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.