Free Support Forum - aspose.com

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.

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" );
}
else
{
f.FillField( "LHeading", "Second Heading" );
}
f.Save();
}

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

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

==============================================================

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

John

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

Please refer to the online Demo http://www.aspose.com/Products/Aspose.Pdf.kit/Demos/, the first sample is very simple which concatenates two PDF files into one.

You can also find the details on how to concatenate at http://www.aspose.com/Wiki/default.aspx/Aspose.Pdf.Kit/ConcatenatePDFDocuments.html.