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

C# PDF Viewer, Reader Library
How to open, display, add, delete, Adobe PDF file attachment using c# in .net web, windows, wpf application


Sample Codes for C#.NET Users to attach files on PDF in C#.NET Class. ASP.NET Annotate PDF function is based on C# PDF Annotate SDK.













C# add attach file annotation to pdf document


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

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

{
    //  create the annotation
    PDFAnnotFileAttach annot = new PDFAnnotFileAttach();

    annot.Position = new PointF(100F, 100F);
    annot.FilePath = @"C:\AttachmentFile.txt";

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

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




C# read attach file annotation from pdf document


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

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is PDFAnnotFileAttach)
    {
        PDFAnnotFileAttach obj = (PDFAnnotFileAttach)annot;
        Console.WriteLine("Color: " + obj.Color.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);