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

Free Support Forum - aspose.com

Concatenate MemoryStreams and save it to Pdf file using PdfFileInfo


I’m looking for concatenate two FileStreams to get one MemoryStream and then, convert it to PDF file.

Both of my input files are PDF files.

PdfFileEditor editor = new PdfFileEditor();

FileStream fs1 = new FileStream(@“C:\Aspose\test1.pdf”, FileMode.Open);
FileStream fs2 = new FileStream(@“C:\Aspose\test2.pdf”, FileMode.Open);

MemoryStream outStream = new MemoryStream();

editor.Concatenate(fileStream1, fileStream2, outStream);

PdfFileInfo fi = new PdfFileInfo(outStream);


An exception occured during the instantiation of “fi”. -> Invalid pdf format:pdf head signature is not found!: v4.2.0.0.

But, when I use the already concatenated file stream by using :
FileStream fs = new FileStream(@“C:\Aspose\concatenate.pdf”, FileMode.Open);

The line :
PdfFileInfo fi = new PdfFileInfo(fs);

works fine…

Have I done something wrong ? Have I used MemoryStream in the wrong way ?

By the way, I know I can get a FileStream instead of my MemoryStream but I want to work without physical files.

Hi Quentin,

Can you please try to add the following statement before passing outStream to the PdfFileInfo object?


If it doesn’t resolve your issue then please share the sample PDF files with us, so we could test the issue at our end.

We’re sorry for the inconvenience.

It works :slight_smile:

Thanks for your help.