add remove attachment in PDF in C#

The PDF format supports adding attachments to a PDF file similar to the email attachments. A PDF attachment could be of TXT, DOCX, XLSX, or any other document format. In this article, you will learn how to implement some basic PDF attachment manipulation features in your .NET applications. By the end of this article, you will be able to extract, add, or remove attachments in a PDF programmatically using C#.

PDF Attachment Manipulation API - Free Download

Aspose.PDF for .NET is a well-known PDF manipulation API that lets you process PDF files seamlessly. You can read, create, edit, and convert the PDF files and manipulate the PDF attachments within a few steps. The API can be downloaded as DLL or MSI as well as installed using NuGet.

Install-Package Aspose.Pdf

Add Attachments to PDF using C#

Aspose.PDF for .NET also allows you to add the attachments to a PDF file. For this, you simply need to add the file to Document.EmbeddedFiles collection using the FileSpecification class. The following are the steps to add an attachment to a PDF document.

The following code sample shows how to add an attachment to a PDF document using C#.

Extract PDF Attachment using C#

First of all, let’s check out how to retrieve attachments from a PDF document. For this, follow the below steps:

The following code sample shows how to extract PDF attachments using C#.

Remove Attachments from PDF using C#

You can either remove all or a particular attachment from a PDF file. For this, Aspose.PDF for .NET provides the following methods:

The following are the steps to delete attachments from a PDF.

The following code sample shows how to remove attachments from a PDF file in C#.

Conclusion

In this article, you have seen how to manipulate the attachments in PDF documents programmatically. The step by step guide, API references, and code samples have shown how to retrieve, add, and remove attachments in PDF files using C#. You can learn more about Aspose.PDF for .NET using the documentation.

See Also