How to Start Convert PDF Read PDF Build PDF 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

Using C# PDF SDK Library
How to create, edit, update, remove PDF file annotations and drawings using C#.NET


Sample Codes for C#.NET Users to create, edit pdf file existing annotations, comments on PDF in C#.NET Class. ASP.NET Annotate PDF function is based on C# PDF Annotate SDK.













C# retrieve all annotations information from a PDFDocument


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

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);

Console.WriteLine("Number of Annotations: " + annots.Count);
if (annots.Count > 0)
{
    foreach (IPDFAnnot annot in annots)
    {
        Console.WriteLine("Annotation");
        Console.WriteLine("  Page:     " + annot.PageIndex);
        Console.WriteLine("  Aritst:   " + annot.Artist);
        Console.WriteLine("  Subject:  " + annot.Subject);
        Console.WriteLine("  Content:  " + annot.Content);
    }
}




C# retrieve all annotations information from a PDF page


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

PDFDocument doc = new PDFDocument(inputFilePath);
PDFPage page = (PDFPage)doc.GetPage(0);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(page);




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




C# retrieve annotation popup note window's properties


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

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is IPDFPopupAnnot)
    {
        Console.WriteLine("Annotation has popup window");

        IPDFPopupAnnot obj = (IPDFPopupAnnot)annot;
        Console.WriteLine("Is open in the begin:  " + obj.Popup.IsOpen);
        Console.WriteLine("Popup window boundary: " + obj.Popup.Boundary.ToString());
    }
    else
    {
        Console.WriteLine("Annotation has no popup window");
    }
}




C# retrieve annotation flags


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

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    Console.WriteLine("Annotation Flags");
    Console.WriteLine("  Invisible:       " + annot.IsInvisible);
    Console.WriteLine("  Hidden:          " + annot.IsHidden);
    Console.WriteLine("  Print:           " + annot.IsPrint);
    Console.WriteLine("  No Zoom:         " + annot.NoZoom);
    Console.WriteLine("  No Rotate:       " + annot.NoRotate);
    Console.WriteLine("  No View:         " + annot.NoView);
    Console.WriteLine("  Read Only:       " + annot.IsReadOnly);
    Console.WriteLine("  Locked:          " + annot.IsLocked);
    Console.WriteLine("  Toggle No View:  " + annot.IsToggleNoView);
    Console.WriteLine("  Locked Contents: " + annot.IsLockedContents);
}




C# set annotation flags


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

//  create the annotation
PDFAnnotDeleteLine annot = new PDFAnnotDeleteLine();
annot.StartPoint = new PointF(100F, 200F);
annot.EndPoint = new PointF(300F, 400F);

//  set annotation flags
annot.IsInvisible = false;
annot.IsPrint = true;
annot.NoRotate = true;
annot.NoZoom = true;

//  add annotation
PDFAnnotHandler.AddAnnotation(inputFilePath, 1, annot, outputFilePath);