The aim of this tutorial is to demonstrate the procedure how to add ellipse annotation in PDF using C#. Annotations are useful in providing additional information, highlighting important sections, and allowing users to add comments to PDF files. The use of ellipse annotations is particularly beneficial when highlighting specific areas or shapes within a PDF. We will provide step-by-step instructions on setting up the annotation library and providing a code example to insert ellipse annotation to PDF in C#. Subsequently, the following section will provide further details on how to add an ellipse to a PDF document using the C# programming language.
Steps to Add ellipse Annotation in PDF using C#
- Install GroupDocs.Annotation for .NET via the NuGet package manager to add an ellipse annotation into PDF
- Include reference of GroupDocs.Annotation namespace
- Instantiate the Annotator class by passing the PDF file’s path as an argument to its constructor
- Instantiate the EllipseAnnotation class and specify the required attributes, such as the position and page number
- Call the Annotator.Add method and pass the EllipseAnnotation object as an argument
- Call the Annotator.Save method to save output PDF
Following the guidelines outlined above and installing the annotation library on any computer, you can quickly and easily create ellipse annotation in PDF using C#. These steps are compatible with popular operating systems like Windows, macOS, and Linux that have .NET installed. It is not necessary to install any additional software to add ellipse annotations to a PDF file. Additionally, the library used in the code example provided is cross-platform, ensuring compatibility across different systems.
Code to Add ellipse Annotation in PDF using C#
using GroupDocs.Annotation.Models.AnnotationModels; | |
using GroupDocs.Annotation.Models; | |
using GroupDocs.Annotation; | |
using System; | |
using System.Collections.Generic; | |
namespace AddEllipseAnnotationinPDFusingCSharp | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Set License to avoid the limitations of Annotation library | |
License lic = new License(); | |
lic.SetLicense(@"GroupDocs.Annotation.lic"); | |
// Instantiate Annotator object by passing path of PDF | |
// file to its constructor | |
using (Annotator annotator = new Annotator("input.pdf")) | |
{ | |
// Create an instance of EllipseAnnotation class | |
// and set some properties | |
EllipseAnnotation ellipse = new EllipseAnnotation | |
{ | |
BackgroundColor = 65535, | |
Box = new Rectangle(100, 100, 100, 100), | |
CreatedOn = DateTime.Now, | |
Message = "This is ellipse annotation", | |
Opacity = 0.7, | |
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 | |
} | |
} | |
}; | |
// Add ellipse annotation to Annotator | |
annotator.Add(ellipse); | |
// Save the final PDF to disk | |
annotator.Save("result.pdf"); | |
} | |
} | |
} | |
} |
The preceding section furnished a comprehensive guide on how to add ellipse annotation in PDF C#, complete with an easy-to-follow code example. Once the document annotation library is installed and the input and output file paths are adjusted as necessary, integrating the code into your applications should be a straightforward process. Congratulations! You have now successfully added an ellipse annotation to a PDF file using C#.
We have previously published an article on how to insert a text field annotation in PDF using C#. For further information, please consult our guide on how to add text field annotation in PDF using C#.