locked
how to save multiple rdlc reports into one pdf file RRS feed

  • Question

  • User-1921852639 posted

    Hello all,

                In our project we are having multiple .rdlc  every report i having seperate pages to display. now we are have to save the reports in one pdf document  can any one suggest me how to achieve this?

     

    Thursday, August 23, 2012 7:15 AM

Answers

  • User-1605278047 posted

    you can use iTextSharp to merge the pdf.

    here are few links for tutorials.
    http://geekswithblogs.net/bsherwin/archive/2007/06/29/113566.aspx
    http://www.suyati.com/SuyatiBlog/2010/12/merge-pdfs-using-itextsharp-c-2/

    or you can use below code it will work with iTextsharp

    public static void CombineMultiplePDFs(string[] fileNames, string outFile) 
        { 
            int pageOffset = 0; 
            ArrayList master = new ArrayList(); 
            int f = 0; 
            Document document = null; 
            PdfCopy writer = null; 
            while (f < fileNames.Length) 
            { 
                // we create a reader for a certain document 
                PdfReader reader = new PdfReader(fileNames[f]); 
                reader.ConsolidateNamedDestinations(); 
                // we retrieve the total number of pages 
                int n = reader.NumberOfPages; 
                pageOffset += n; 
                if (f == 0) 
                { 
                    // step 1: creation of a document-object 
                    document = new Document(reader.GetPageSizeWithRotation(1)); 
                    // step 2: we create a writer that listens to the document 
                    writer = new PdfCopy(document, new FileStream(outFile, FileMode.Create)); 
                    // step 3: we open the document 
                    document.Open(); 
                } 
                // step 4: we add content 
                for (int i = 0; i < n; ) 
                { 
                    ++i; 
                    if (writer != null) 
                    { 
                        PdfImportedPage page = writer.GetImportedPage(reader, i); 
                        writer.AddPage(page); 
                    } 
                } 
                PRAcroForm form = reader.AcroForm; 
                if (form != null && writer != null) 
                { 
                    writer.CopyAcroForm(reader); 
                } 
                f++; 
            } 
            // step 5: we close the document 
            if (document != null) 
            { 
                document.Close(); 
            } 
        } 
    



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 4:26 PM