FileStream[] inputStreams = new FileStream[2];<o:p></o:p>
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;
byte[] baPDFout = new byte[intLength];
//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 client's browser, you may simply call pfe.Concatenate(inputStreams,Response); overloaded method where you can simply pass Response object as an argument and it will save you from storing the resultant file in MemoryStream object, create a Byte array and then pass the contents of Byte array to Response object. When using this approach, the code will be simplified as shown below
[C#]
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 use MemoryStream.ToArray(). Please take a look over following code snippet.
[C#]
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);