Wednesday, 11 March 2015

Merge two or More PDF into a single PDF using PDFSharp Library in SharePoint 2010


Need  to merge two or more PDFs into a single PDF in SharePoint 2010


I have searched around web for the solution and it seems many third Party dlls like itextsharp,selectPDF, PDFSharp etc are available to achieve this functionality. I go with PDFsharp free Licence.

Download the PDFsharp  dll

Below is the code :

arrFilesToZip - This is array list to store all the PDF file location which you want to merge.
CombinedFilePath - This  is the Merge PDF file full path URL

                PdfDocument outputDocument = new PdfDocument();

                // Iterate files
                foreach (object tmpfile in arrFilesToZip)
                    string file = (string)tmpfile;
                    // Open the document to import pages from it.

                    PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);

                    // Iterate pages

                    int count = inputDocument.PageCount;
                    for (int idx = 0; idx < count; idx++)
                        // Get the page from the external document...
                        PdfPage page = inputDocument.Pages[idx];

                        // ...and add it to the output document.


                // Save the document...

                string combinedFilesPdfName = "CombinedFilePath"+".pdf";
                //  if (File.Exists(combinedFilesPdfName))
                //      File.Delete(combinedFilesPdfName);


Please let me know if you face any issue in merge of the files using this code.



  1. Thanks, but is there any, don't know, easier options for a common user?

    1. You can find lot easier option if you buy the Acrobat or some Licensed Product. This Example for Developers who wants to Merge two PDF using Open Source DLLs

  2. You likewise have the choice to put the connection on an iFrame tab together with some data. Along these lines, you have a different page for the PDF records you'd get a kick out of the chance to share on Facebook.