XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to 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
PDF attach file annotate
  |  
Home ›› XDoc.PDF ›› C# PDF: Attach file annotation

How to attach files in PDF using C#


Sample Codes for C#.NET Users to attach files on PDF in C#.NET Class






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