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 Annotation 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.





In this C# tutorial, you will learn how to add, insert attachment file to PDF using C# in ASP.NET MVC Web, Windows applications.

  • Quick to insert an existing attach file to PDF document with specified page position
  • Read, extract an existing attach file information from PDF





C# add attach file annotation to pdf document


In this C# tutorial, you will learn how to add, insert attachment file to PDF using C# in ASP.NET MVC Web, Windows applications.

  • Create a PDFDocument object from an existing PDF file, and get the first page of the PDF document
  • Define a new attach file annotation object PDFAnnotFileAttach, and specify the page position and attached file path
  • Add attach file annotation to the PDF page
  • Save the modified PDF document and output to a new PDF file



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