Free Support Forum - aspose.com

Concatenate MemoryStreams and save it to Pdf file using PdfFileInfo

Hi,

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);

fi.SaveNewInfo(fileName);

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?

outStream.Seek(0,SeekOrigin.Begin);

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.
Regards,

It works :slight_smile:

Thanks for your help.