Combining multiple PDFs using PDFSharp

I don't sure about my answer. Please read your self.

http://www.go4coding.com/post/2011/05/26/Merging-PDF-files-into-single-PDF-in-CSharp-using-PDFSharp.aspx

private static void MergeMultiplePDFIntoSinglePDF(string outputFilePath, string[] pdfFiles)
{
    Console.WriteLine("Merging started.....");
    PdfDocument outputPDFDocument = new PdfDocument(); 
    foreach (string pdfFile in pdfFiles)
    {
        PdfDocument inputPDFDocument = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Import);
        outputPDFDocument.Version = inputPDFDocument.Version; 
        foreach (PdfPage page in inputPDFDocument.Pages)
        {
            outputPDFDocument.AddPage(page);
        }
    }
    outputPDFDocument.Save(outputFilePath); 
    Console.WriteLine("Merging Completed");
}

I have come to believe that it might be the input PDFs that are corrupt or unreadable to PDFSharp. There are several examples of SSRS PDFs not being readable to PDF-libraries or even Adobe's Reader. For example here:

http://www.sqldev.org/sql-server-reporting-services/export-pdf-in-ssrs-2008-vs-ssrs-2005--pdf-is-different-wont-work-with-itextsharp-possibly-other-13968.shtml

... and here:

https://stackoverflow.com/questions/2393175/ssrs-2008-pdf-files-cannot-be-opened

... AND most importantly on the PDFSharp forum:

http://forum.pdfsharp.net/viewtopic.php?f=2&t=674

I don't know if this is the bug you're encountering - the message is strange - but it seems likely to have something to do with that, when you take in to consideration that your code sample works flawlessly with any PDF I tried (I don't have any SQL Server Reports to try out, though)


First of all, thank you for your feedback. The problem doesn't come from the compression because I have <humanreadalble>true</humanreadable> in my device info string, otherwise PDFSharp just can't see anything in the PDF.

I tried recompiling PDFSharp from the latest source code, and it worked... It doesn't throw the exception anymore. The weird thing is that I checked the version of my dll and it was the same as the latest build. Maybe they fixed something without incrementing the version ?

Anyway, thanks for your assistance. I accepted your post as the answer to show my appreciation.