XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Text Callout
  |  
Home ›› XDoc.PDF ›› C# PDF: Text callout annotation

How to add, retrieve, delete PDF text callout annotations using C#.NET


Sample Codes for C#.NET Users to edit text callout on PDF in C#.NET Class






C# add text callout annotation to 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





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);