Concatenate Memory Streams


I am looking for a way to concatenate 2 or more word or cell objects i just created/loaded into memory, without having to save it to a pdf file first. I can load an excel and word file into a memory stream and convert them to pdf (if necessary) as shown below. The problem occurs when I try to concatenate the memory streams. I can save them to disk then load the newly created pdfs as FileStreams and concatenate them into a single pdf with the PDFFileEditor but I would prefer to do this without having to save unnecessary files. Any suggestions?

Dim wordPDFFile As New System.IO.MemoryStream()

Dim cellPDFFile As New System.IO.MemoryStream()

Dim msWord As New System.IO.MemoryStream()

Dim msCell As New System.IO.MemoryStream()

Dim pdfExcel As New Aspose.Pdf.Pdf()

Dim pdfWord As New Aspose.Pdf.Pdf()

'Load Word Document

Dim wd As New Aspose.Words.Document("WordFile1.doc")

wd.Save(msWord, Aspose.Words.SaveFormat.AsposePdf)

pdfWord.BindXML(msWord, Nothing)


'Load Excel Document

Dim xls As New Aspose.Cells.Workbook()


xls.Save(msCell, Aspose.Cells.FileFormatType.AsposePdf)

pdfExcel.BindXML(msCell, Nothing)


Dim outputStream As FileStream = New FileStream("out.pdf",FileMode.Create)

Dim editor As Aspose.Pdf.Kit.PdfFileEditor = New Aspose.Pdf.Kit.PdfFileEditor

editor.Concatenate(wordPDFFile , cellPDFFile, outputStream)

Please try to seek stream object to the beginning before calling method Concatenate.

wordPDFFile.Seek(0, SeekOrigin.Begin)

cellPDFFile.Seek(0, SeekOrigin.Begin)

Thanks for the quick response Kevin. Overlooking my code I wrote (not the code posted) I realized I made a mistake and didn't clear the memory one the memory streams causing there to be extra bytes in the stream, The concatenate function does work with or without setting the memory stream to start position.

Embarrassed [:$] I apologize for the confusion, thank you for the assistance.