Unable to extract attachments from pdf document

Dear Aspose Team,


Please find attached pdf file. I am using the below code to extract the attachments from a pdf document. But it is showing the embedded files count as 0.

var attachments = pdfDocument.EmbeddedFiles;

Please let me know whether this is an issue inside Aspose.Pdf or not.

Thanks & Regards,
N.Murali Krishna.

Hi Murali,


Thanks for your patience. We have further investigated the issue, please note that there are 2 types of attachments (embedded files):
  1. Attachments come through PDF document catalog
  2. Attachments come through page, file attachment annotations.
Your shared document has second type of attachments i.e file attachment annotation. So please use following code snippet to extract these files.

Document pdf = new
Document(myDir + “attachfile.pdf”);<o:p></o:p>

int count = 0;<o:p></o:p>

foreach (Aspose.Pdf.Page
page in pdf.Pages)<o:p></o:p>

{<o:p></o:p>

foreach (Aspose.Pdf.InteractiveFeatures.Annotations.Annotation annot in
page.Annotations)<o:p></o:p>

{<o:p></o:p>

if (annot is FileAttachmentAnnotation)<o:p></o:p>

{<o:p></o:p>

Console.WriteLine((annot as
FileAttachmentAnnotation).File.Params.CreationDate);<o:p></o:p>

Console.WriteLine((annot as
FileAttachmentAnnotation).File.Params.ModDate);<o:p></o:p>

Console.WriteLine((annot as
FileAttachmentAnnotation).File.Params.Size);<o:p></o:p>

Console.WriteLine((annot as
FileAttachmentAnnotation).File.Name);<o:p></o:p>


count++;<o:p></o:p>

FileAttachmentAnnotation
attachment = (annot as FileAttachmentAnnotation);<o:p></o:p>

using (BinaryReader
reader = new BinaryReader(attachment.File.Contents))<o:p></o:p>

using (BinaryWriter
writer = new BinaryWriter(new FileStream(myDir

  • Path.GetFileName(attachment.File.Name), FileMode.Create)))<o:p></o:p>


    writer.Write(reader.ReadBytes((int)attachment.File.Contents.Length));<o:p></o:p>

    }<o:p></o:p>

    }<o:p></o:p>

    }<o:p></o:p>

Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,


Thanks for the solution and it worked, thank you very much for the support.

Thanks & Regards,
N.Murali Krishna.

Hi Murali,


Thanks for your feedback. It is good to know that you have managed to accomplish your requirement.

Please keep using our API and feel free to ask any question or concern, we will be more than happy to extend our support.

Best Regards,