Recently one of my colleague asked me is there anyway to programmatically merge huge number of PDF files in to a single file, without using Adobe Acrobat libraries, well the answer is yeah. and there are a lot of off the shelve and open source libraries available for this. the best one I found is the PDFSharp, and its totally FREE.
Here is a little introduction about PDFSharp:
- PDFsharp is the Open Source library that easily creates PDF documents from any .NET language.
The same drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer. - It can use either GDI+ or WPF.
- It includes support for Unicode in PDF files.
- It also includes MigraDoc Lite which brings you all the high-level functionality not included in PDFsharp.
Using PDFSharp is very simple. the samples in the official download file are more than enough to learn the functionality of PDFSharp.here is a little piece of code I used to merge A collection of PDFs in a folder to a single PDF file.
1: PdfDocument inputDocument=
2: PdfReader.Open(file.FullName,PdfDocumentOpenMode.Import);
3: int count = inputDocument.PageCount;
4: for (int idx = 0; idx < count; idx++)
5: {
6: // Get the page from the external document…
7: PdfPage page = inputDocument.Pages[idx];
8: // …and add it to the output document.
9: outputDocument.AddPage(page);
10: }
11:
12: outputDocument.Save(filename);
if you want to download the full sample I created download it here.
if you want to download pdfSharp Library visit the site below:
http://www.pdfsharp.com/PDFsharp



July 24th, 2008 at 8:33 pm
Awesome! I was messing with iTextSharp, Gio’s implementation at Code Project and Adobe’s conflaguration and nothing was working for the files I was using. This one did though… THANK YOU!
July 25th, 2008 at 12:23 pm
I’ve used iTextSharp and it’s a very mature product. I would be concerned that this one is missing some critical feature. Thanks for bringing it to my attention, I’ll have to try using it to see if is better and/or easier.
July 27th, 2008 at 9:09 pm
As an alternative there is simple program Pdftk - PDF toolkit, that do merge of existing documents and even more. http://www.accesspdf.com/pdftk/