How to Add Image Annotation to PDF Using C#

In this article, we will explore the process how to add image annotation to PDF using C# with the help of most popular annotation library. PDF documents are widely used for storing and sharing information, including images. However, sometimes you may need to add image annotations in PDF files to provide more context or to highlight specific details. We will also assist you in composing a code sample that demonstrates how to insert image annotation into PDF using C#. Here are the essential steps to follow when incorporating an image annotation into a PDF using the C# programming language.

Steps to Add Image Annotation to PDF Using C#

  1. Install GroupDocs.Annotation for .NET with the help of NuGet package manager
  2. Include reference of GroupDocs.Annotation namespace
  3. Initialize the object of Annotator class by passing PDF file’s path to its constructor
  4. Instantiate the ImageAnnotation class and assign values to various properties, such as the location, opacity, and page number
  5. Call the Annotator.Add method and provide the ImageAnnotation object as an argument
  6. Call the Annotator.Save method to save output PDF

The instructions outlined above demonstrate how to install the annotation library on your computer to enable the procedure to create image annotation in PDF using C#. These steps can be carried out on various widely used operating systems, including Windows, macOS, and Linux, provided that .NET is installed. To insert an image into PDF document, no extra software is necessary. Moreover, the library utilized in the following code example is compatible with multiple platforms.

Code to Add Image Annotation to PDF Using C#

using GroupDocs.Annotation;
using GroupDocs.Annotation.Models;
using GroupDocs.Annotation.Models.AnnotationModels;
namespace AddImageAnnotationtoPDFUsingCSharp
{
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 ImageAnnotation class
// and set some properties
ImageAnnotation area = new ImageAnnotation
{
Box = new Rectangle(100, 100, 100, 100),
Opacity = 0.7,
PageNumber = 0,
ImagePath = "image.png",
Angle = 100
};
// Add image annotation to Annotator
annotator.Add(area);
// Save the final PDF to disk
annotator.Save("result.pdf");
}
}
}
}

In the preceding section, we presented a detailed description of incorporating an image annotation into a PDF file using C# and provided a simple code example. The process of C# image annotation in PDF is very simple. Once you have installed the annotation library and adjusted the input and output file paths as necessary, you can seamlessly incorporate the code into your applications. Congratulations! You have now successfully implemented an image annotation in a PDF file using C#.

We have previously published a topic about incorporating distance annotations into PDF files. If you need further details, please consult our guide on how to add distance annotation in PDF using C#.

 English