This article aims to guide you through the procedure how to add underline annotation into PDF using C# with the assistance of commonly used annotation library. Annotations such as underlines, highlights, and comments can make it easier to read and understand the content of a PDF document. The primary focus of this article will be on how to insert underline annotation in PDF using C#, and we will showcase this with a code sample. Here are the necessary steps you should follow to achieve it.
Steps to Add Underline Annotation into PDF Using C#
- Use NuGet package manager to install GroupDocs.Annotation for .NET
- Add namespace reference of GroupDocs.Annotation into your project
- Create an object of Annotator class by passing PDF file’s path to its constructor
- Create an instance of UnderlineAnnotation class and set some properties, e.g. page number, font color etc.
- Call the Add method of the Annotator class, providing the UnderlineAnnotation object as its argument
- Call the Annotator.Save method to save final output PDF to disk
The above instructions explain how to install the annotation library on your computer, enabling you to create underline annotation to PDF in C#. You don’t need any additional software to use annotation library for the insertion of underline annotation. As long as .NET is installed, these instructions can be used on widely used operating systems such as Windows, macOS, and Linux. Following code example shows the insertion of underline annotation in PDF.
Code to Add Underline Annotation into PDF Using C#
using GroupDocs.Annotation; | |
using GroupDocs.Annotation.Models; | |
using GroupDocs.Annotation.Models.AnnotationModels; | |
using System.Collections.Generic; | |
using System; | |
namespace AddUnderlineAnnotationintoPDFUsingCSharp | |
{ | |
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 UnderlineAnnotation class | |
// and set some properties | |
UnderlineAnnotation underline = new UnderlineAnnotation | |
{ | |
CreatedOn = DateTime.Now, | |
FontColor = 65535, | |
BackgroundColor = 16761035, | |
Message = "This is underline annotation", | |
Opacity = 0.7, | |
PageNumber = 0, | |
UnderlineColor = 1422623, //Supported only Word and PDF documents | |
Points = new List<Point> | |
{ | |
new Point(80, 730), new Point(240, 730), | |
new Point(80, 650), new Point(240, 650) | |
}, | |
Replies = new List<Reply> | |
{ | |
new Reply | |
{ | |
Comment = "First comment", | |
RepliedOn = DateTime.Now | |
}, | |
new Reply | |
{ | |
Comment = "Second comment", | |
RepliedOn = DateTime.Now | |
} | |
} | |
}; | |
// Add underline annotation to Annotator | |
annotator.Add(underline); | |
// Save the final PDF to disk | |
annotator.Save("result.pdf"); | |
} | |
} | |
} | |
} |
In the preceding portion, a thorough description of C# underline annotation in PDF was provided, along with an uncomplicated code demonstration. After installing the annotation library and making any necessary adjustments to the input and output file paths, you can effortlessly incorporate the code into your applications. Congratulations! You have effectively inserted an underline annotation into a PDF file utilizing C#.
We have previously published a topic about incorporating image annotations into PDF files. If you need further details, please consult our guide on how to add image annotation in PDF using C#.