Adding Attachement From Stream

Hi,


I have a PDF document. I need to attach various files into this. Can this be done from a stream?

Its not clear from this whether this is achievable:

https://docs.aspose.com/pdf/net/attachments/

Thanks.

Hi Andrew,

Thanks for using our API’s.

The FileSpecification constructor has an overload to load attachment through Stream object but during my testing, I have observed that attachments loaded with this method are broken in resultant file. For the sake of correction, I have logged it as PDFNET-41474 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

[C#]

// Open document
Document pdfDocument = new Document("c:/pdftest/56A_38853.pdf");

// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification(new FileStream("c:/pdftest/PDF_File_Security_Settings.PNG", FileMode.Open) , "Sample Imge file");

// Add attachment to document's attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification);

// Save new output
pdfDocument.Save(“c:/pdftest/Attachment_from_Stream.pdf”);

Hi,


Can I have an update please?

Hi Andrew,


Thanks for your inquiry. I am afraid the reported issue is still not resolved as we have recently noticed it. We will notify you soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience.

Best Regards,

Hi Andrew,

Thanks for your patience.

We have further investigated earlier reported PDFNET-41474 and in order to generated correct output, please try using following code snippet (pleas specify attachment file name to generate correct output).

[C#]

Document pdfDocument = new Document(“c:/pdftest/Converted.pdf”);
// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification(new FileStream("c:/pdftest/Form_Display.PNG", FileMode.Open), "Sample Imge file");
fileSpecification.Name = "Form_Display.PNG";
// Add attachment to document's attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification);
// Save new output
pdfDocument.Save(“c:/pdftest/Attachment_from_Stream.pdf”);