Free Support Forum -

Can I get a good c# example of concatenating two or more PDF's

I want to use the constructor that has the memorystreams as the signature.


Thanks for considering Aspose.

Multiple PDF documents can be merged or concatenated together into a a single PDF file. Just instantiate the PdfFileEditor object of the component Aspose.Pdf.Kit and call its Concatenate method to acomplish this task.

Here are sample codes from one of our users which is very representative.


string templateFilename = "PortStateReport.pdf";
MemoryStream[] pdfStreams = new MemoryStream[2];
for ( int index = 0; index < pdfStreams.Length; index++ )
pdfStreams[index] = new MemoryStream();
Aspose.Pdf.Kit.Form f = new Aspose.Pdf.Kit.Form(templateFilename,pdfStreams[index]);
if ( index == 0 )
f.FillField( "LHeading", "First Heading" );
f.FillField( "LHeading", "Second Heading" );

MemoryStream outputStream = new MemoryStream();
Aspose.Pdf.Kit.PdfFileEditor pdfFileEditor = new Aspose.Pdf.Kit.PdfFileEditor();

using ( FileStream fs = new FileStream("Success.pdf",FileMode.Create, FileAccess.ReadWrite ) )
byte[] buffer = new byte[outputStream.Length];
//outputStream.Position = 0;


It seems like this only works before the PDF's are flattened. Can I concatenate documents that have been Flattened?


The codes above are just an example illustrating the concatenation on the PDF forms.

Please refer to the online Demo, the first sample is very simple which concatenates two PDF files into one.

You can also find the details on how to concatenate at