Extract and Save an Attachment

Get All Attachments

With Aspose.PDF, it is possible to get all attachments from a PDF document. This is useful either when you want to save the documents separately from the PDF, or if you need to strip a PDF of attachments.

To get all attachments from a PDF file:

  1. Loop through the Document object’s EmbeddedFiles collection. The EmbeddedFiles collection contains all attachments. Each element of this collection represents a FileSpecification object. Each iteration of the foreach loop through the EmbeddedFiles collection returns a FileSpecification object.
  2. Once the object is available, retrieve either all the attached file’s properties or the file itself.

The following code snippets show how to get all the attachments from a PDF document.

The following code snippet also work with Aspose.PDF.Drawing library.

Get Individual Attachment

In order to get an individual attachment, we can specify the index of attachment in EmbeddedFiles object of Document instance. Please try using following code snippet.

Get Attachments that contains in FileAttachmentAnnotation objects

In addition to the Document object’s EmbeddedFiles collection, Attachments can also be contained in FileAttachmentAnnotation objects. Below is the code for viewing the number and details of such Attachments.