Extract Attachments from PDF File

Contents
[ ]

One of the main category under the extraction capabilities of Aspose.Pdf.Facades namespace is the attachment extraction. This category provides a set of methods, which not only help extract the attachments but also provides the methods which can give you the attachment related information i.e. GetAttachmentInfo and GetAttachName methods provide attachment information and attachment name respectively. In order to extract and then get attachments we use ExtractAttachment and GetAttachment methods.

The following code snippet shows you how to use PdfExtractor methods:

public static void ExtractAttachments()
{
    PdfExtractor pdfExtractor = new PdfExtractor();
    pdfExtractor.BindPdf(dataDir + "sample-attach.pdf");

    // Extract attachments
    pdfExtractor.ExtractAttachment();

    // Get attachment names
    if (pdfExtractor.GetAttachNames().Count > 0)
    {
         Console.WriteLine("Extracting and storing...");
         // Get extracted attachments
         pdfExtractor.GetAttachment(dataDir);
    }
}