Hi Geoffrey,
Thanks for your patience.
We have further investigated this issue and have found that the reason for this problem can be the fact that the Seek call to memory stream msPDFout object is missing which eventually causes an empty resultant data array (baPDFOut). Please try using the following code snippet with the latest release version of Aspose.Pdf for .NET 7.0.0 and in case you still face a similar problem or you have any further query, please feel free to contact.
FileStream[] inputStreams = new FileStream[2];
inputStreams[0] = new FileStream("D:\\pdftest\\OutputPDF.pdf", FileMode.Open);
inputStreams[1] = new FileStream("D:\\pdftest\\input(3).pdf", FileMode.Open);
MemoryStream msPDFout = new MemoryStream();
//create a new PDF Kit object
PdfFileEditor pfe = new PdfFileEditor();
//concatenate the Attachments
pfe.Concatenate(inputStreams, msPDFout);
//make a new Byte[] to pass to the output screen
int intLength = (int)msPDFout.Length;
//move pointer of the stream to begin
msPDFout.Seek(0, SeekOrigin.Begin);
msPDFout.Read(baPDFout, 0, intLength);
//Context.Session.Add("ApplicationPDF", baPDFout);
//Context.Response.Redirect("DisplayPDF.aspx", false);
Response.ContentType = "Application/pdf";
Context.Response.OutputStream.Write(baPDFout, 0, intLength);
Besides this, if you need to display the resultant PDF in the client’s browser, you may simply call pfe.Concatenate(inputStreams,Response) overloaded method where you can simply pass the Response object as an argument and it will save you from storing the resultant file in the MemoryStream object, create a Byte array and then pass the contents of the Byte array to the Response object. When using this approach, the code will be simplified as shown below.
FileStream[] inputStreams = new FileStream[2];
inputStreams[0] = new FileStream("D:\\pdftest\\OutputPDF.pdf", FileMode.Open);
inputStreams[1] = new FileStream("D:\\pdftest\\input(3).pdf", FileMode.Open);
MemoryStream msPDFout = new MemoryStream();
//create a new PDF Kit object
PdfFileEditor pfe = new PdfFileEditor();
//concatenate the Attachments
pfe.Concatenate(inputStreams, Response);
In case you still need to use MemoryStream, then the more efficient way is not to create a new array but to use MemoryStream.ToArray(). Please look over the following code snippet.
FileStream[] inputStreams = new FileStream[2];
inputStreams[0] = new FileStream("D:\\pdftest\\OutputPDF.pdf", FileMode.Open);
inputStreams[1] = new FileStream("D:\\pdftest\\input(3).pdf", FileMode.Open);
MemoryStream msPDFout = new MemoryStream();
//create a new PDF Kit object
PdfFileEditor pfe = new PdfFileEditor();
//concatenate the Attachments
pfe.Concatenate(inputStreams, msPDFout);
//make a new Byte[] to pass to the output screen
int intLength = (int)msPDFout.Length;
// Remove this code portion
//byte[] baPDFout = new byte[intLength];
//move pointer of the stream to begin
//msPDFout.Read(baPDFout, 0, intLength);
//Context.Session.Add("ApplicationPDF", baPDFout);
//Context.Response.Redirect("DisplayPDF.aspx", false);
Response.ContentType = "Application/pdf";
Context.Response.OutputStream.Write(msPDFout.ToArray(), 0, intLength);