Problems Reading Attachments from PDF with EmbeddedFiles


I tried the code provided at Working with Attachments in PDF|Aspose.PDF for .NET

But no attachment was found even I can see the attachment in Adobe.
The PDF was formerly created with Acrobat PDFMaker 22 tool.

Please tell me how I can access the attachment correctly.


PS: the code I used

// Open document
Document pdfDocument = new Document(@“c:\temp\DownloadablesWithAttachmentsTest.pdf”);
// Get embedded files collection
EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles;
// Get count of the embedded files
Console.WriteLine(“Total files : {0}”, embeddedFiles.Count);
// Loop through the collection to get all the attachments
foreach (FileSpecification fileSpecification in embeddedFiles)
Console.WriteLine(“Name: {0}”, fileSpecification.Name);
Console.WriteLine(“Description: {0}”, fileSpecification.Description);
Console.WriteLine(“Mime Type: {0}”, fileSpecification.MIMEType);
// Check if parameter object contains the parameters
if (fileSpecification.Params != null)
Console.WriteLine(“CheckSum: {0}”, fileSpecification.Params.CheckSum);
Console.WriteLine(“Creation Date: {0}”, fileSpecification.Params.CreationDate);
Console.WriteLine(“Modification Date: {0}”, fileSpecification.Params.ModDate);
Console.WriteLine(“Size: {0}”, fileSpecification.Params.Size);
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0, fileContent.Length);
FileStream fileStream = new FileStream(fileSpecification.Name, FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);

Can you provide a file with which this happens?

Unable to check with the file, I can only assume that the attached files in the document are possible are represented by Fileattachmentannotation annotations.
I will make an example of code so that it is easier for you to check it.

Document pdfDocument = new Document(@"FileWithAttachment.pdf");

foreach (Annotation annotation in pdfDocument.Pages[1].Annotations)
    if (annotation is FileAttachmentAnnotation)
        FileSpecification file = (annotation as FileAttachmentAnnotation).File;
        if (file != null && file.Name != null)
            Debug.WriteLine($"Name: {file.Name} on page 1");

Hello Sergei77,

Thank you for your reply, I tried the code snippet provided but it did not work either. I have attached the pdf file, can you please take a look?

document.pdf (720.4 KB)

Sure, I will look into it and will get back to you soon

I checked with attached document.
pdfDocument.EmbeddedFiles is empty when opened, but FileAttachmentAnnotation objects are present and correspond to files shown as attached in Acrobat. (I attached debug screenshort).
Att.png (20.7 КБ)
Strange that it didn’t work for you. Could it be the reason that in the code that I have attached, Debug is used to display messages, and not Console (underlined on the attached screen)?

Looks like the issue is because I was using the evaluation license for Aspose Pdf, it allows me to see only the first 4 Annotations which doesn’t include the FileAttachmentAnnotation objects. Thanks for your help.

Thank you for your explanation.
Yes, there are 16 annotations (this can be seen in pdfDocument.Pages[1].Annotations.Count even with an unconnected license). And when I disabled the license, to line with the FileAttachmentAnnotation did not enter.
It is possible to try to remove some of the annotations (manually or using the library) and see the result.