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

Free Support Forum - aspose.com

Appending existing PDF to PDF being generated in memory

I have a requirement to create a PDF from attachments in an email that may include images, text, PDFs, html etc… The attachments need to be added in order to the generated PDF and the generated PDF needs to be returned as a byte array. When it comes to the attached PDFs I can’t seem to find a way to add them to the generated PDF except at the very end. I am adding them with the following code:

PdfFileEditor editor = new PdfFileEditor();
var currentStream = new MemoryStream(pdf.GetBuffer());
var concatenateStream = new MemoryStream();
concatenateStream.SetLength(currentStream.Length + stream4.Length);
var success = editor.Concatenate(currentStream, stream4, concatenateStream);

The variable pdf represents the in-memory pdf while stream4 represents the attached PDF as an in-memory stream. I can do this after all of the other non PDFs have been added and then call:

return concatenateStream.GetBuffer();

to return the byte array.

I can’t seem to find a way to get the concatenated stream back into an in-memory pdf so that I can continue to add other attachments.

Thanks in advance

Hi Gerald,

Thanks for your interest in our products.

You can add other file in concatenated stream by loading the file in another stream instead of writting the stream in-memory PDF and after concatenating all the files using streams, finally you can write the final stream in PDF format. For more details, please visit: Concatenate multiple PDF files using MemoryStreams

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,