We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue in adding document attachment

Hi Support,
I am unable to add the attached file as document attachment using Aspose.PDF version 20.7.

My add attachment code snippet is following:

using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(new 
MemoryStream(_documentBytes, true)))
using (MemoryStream msDoc = new MemoryStream(fileAttachement.Bytes))
using (Aspose.Pdf.FileSpecification fileSpecification = new 
Aspose.Pdf.FileSpecification(msDoc, fileAttachement.Name))
       using (MemoryStream msOutput = new MemoryStream())
            fileAttachement.DocBytes = msOutput.ToArray();
            _documentBytes = fileAttachement.DocBytes;

File to add as attachment.zip (4.0 KB)



Would you kindly share complete code snippet and error details that you are facing while adding the attachment. There are some variable in your code snippet which definition is missing. Furthermore, please also share a sample PDF document that you are using. We tested using following code snippet and were unable to notice any issue:

Document pdfDocument = new Document();
FileSpecification fileSpecification = new FileSpecification(dataDir + "Koropi Press.joboptions", "Sample file");
dataDir = dataDir + "AddAttachment_out.pdf";

AddAttachment_out.pdf (5.8 KB)

Hi @asad.ali
I have tried with the code provided in last comment but I am unable to add any attachment in the attached document.
Attachment document issue.zip (2.2 MB)

The code snippet shared earlier is complete whereas _documentBytes are the document bytes in which attachment is being added and fileAttachment.Bytes are the bytes of attachment being added in the document.

Above line throws following error:
Exception on adding attachment.png (50.2 KB)

Could you look into the document and check the issue.


We were able to replicate the issue in our environment with your shared PDF file. We have logged it as PDFNET-48546 in our issue tracking system and will inform you as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any update on it?


Regretfully, the earlier logged ticket is not yet resolved. However, we have recorded your concerns and will surely let you know once it is fully investigated and an ETA is available about its fix. Please give us some time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-48546) have been fixed in Aspose.PDF for .NET 22.1.