PM > Install-Package XDoc.PDF

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








Common Asked Questions

What are PDF file attachment settings?

The PDF attachment feature allows other files to be embedded in a PDF. It allows you to add images, documents, spreadsheets, and multimedia files, such as audio, video, and more within a single PDF. Using RasterEdge XDoc.PDF C# library, you can easily add, remove attached file on a PDF file in your C# ASP.NET web applications.

How to see PDF attachment?

If you open and read a PDF document using Acrobar reader, you can find the attached file in the Attachment pane. RasterEdge EdgePDF ASP.NET PDF viewer and editor allows you to view, edit file attachment on PDF on the web browser in your ASP.NET Core web app. You can also use C# PDF library to add, remove file from PDF file in your C# program.

How to attach file in PDF free?

You can easily attach a file to a PDF document using Acrobat. Open the PDF file using Acrobat, go to menu Insert > Attach File in PDF. You can also use XDoc.PDF C# library to add file to PDF document in your C# ASP.NET MVC web and WinForms, WPF Windows apps.

What is the attachment type of a PDF?

You can add images, Word or PDF documents, spreadsheets, pptx, audio, video files to a PDF document. Using C# PDF library, you can easily add files to a PDF document within few lines of C# source codes.

Why can't I open PDF attachments?

You need a installed PDF reader software to open the PDF document, and open the attached file inside the PDF document. You can directly extract the PDF document attached file content in your C# ASP.NET Core MVC web app using C# PDF library.

How to remove attachment from pdf file?

Most of the PDF editor softwares or online tools support removing attached files from the PDF document. Using XDoc.PDF C# library, you can insert, delete files from PDF document in your C# .NET projects.