How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Text Annotation Library
How to add, edit, retrieve, delete PDF file text callout annotations using C#.NET


Sample Codes for C#.NET Users to edit text callout on PDF in C#.NET Class. ASP.NET Annotate PDF function is based on C# PDF Annotate SDK.





In this tutorial, you learn how to add, read, remove "Text callout" annotation from pdf file in C#.

How to add, remove Text callout annotation to existing PDF file using C#

  1. Download XDoc.PDF Annotation C# library
  2. Install C# library to add text annotation to PDF document
  3. Step by Step Tutorial












C# add text callout annotation to pdf document


The following C# example code will explain how to add, insert a "Text callout annotation" to a PDF page.

  • Get the PDF page object PDFPage to add annotation
  • Create a new PDFAnnotTextCallout object
  • Set the text annotation position and covered area
  • Set the text annotation content
  • Save the PDF document



String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_10.pdf";

//  open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
//  get the 1st page
PDFPage page = (PDFPage)doc.GetPage(0);

//  create the annotation
PDFAnnotTextCallout annot = new PDFAnnotTextCallout();

annot.StartPoint = new PointF(100F, 100F);
annot.Boundary = new RectangleF(400F, 500F, 300F, 80F);

annot.Content = @"This is a text callout annotation";

//  add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);

//  save to a new file
doc.Save(outputFilePath);




C# read text callout annotation from pdf document


The following C# code will show how to read text callout annotations from the pdf document. For each text callout annotation object, you will get the following information.

  • Boundary: the annotation covered area
  • Border color: the text annotation border color
  • Border width: the text annotation border width
  • Fill color: the text annotation fill color



String inputFilePath = Program.RootPath + "\\" + "Annot_10.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is PDFAnnotTextCallout)
    {
        PDFAnnotTextCallout obj = (PDFAnnotTextCallout)annot;
        Console.WriteLine("Textbox Boundary: " + obj.GetTextBoxBoundary().ToString());
        Console.WriteLine("Textbox Border Color: " + obj.LineColor.ToString());
        Console.WriteLine("Textbox Border Width: " + obj.LineWidth);
        Console.WriteLine("Textbox Fill Color: " + obj.FillColor.ToString());
        Console.WriteLine("Callout Line: ");
        foreach (PointF pt in obj.GetEndPoints())
        {
            Console.WriteLine("  " + pt.ToString());
        }
    }
}




C# delete all annotations from pdf document


String inputFilePath = Program.RootPath + "\\" + "1_Annots.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
//  get all annotations in the 1st page
PDFPage page = (PDFPage)doc.GetPage(0);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(page);
//  remove all annotations in the 1st page
PDFAnnotHandler.DeleteAnnotation(doc, annots);