Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to generate 10 reports one by one taking data from database and then trying to merge all into one output pdf. I have a design in a.rdlc form. Here is my C# code:
C#
var db = Database.Open("dbConnection");
    var data = db.QuerySingle("select name from customer_table where id = 2");            
  


    Microsoft.Reporting.WebForms.ReportViewer RptVr = new   Microsoft.Reporting.WebForms.ReportViewer();
    
        RptVr.LocalReport.ReportPath = "~/report/a.rdlc";
    
    RptVr.LocalReport.EnableExternalImages = true;

    Microsoft.Reporting.WebForms.ReportParameter[] x = new Microsoft.Reporting.WebForms.ReportParameter[1];
  
    var fname = "";
    
        fname = "inline; filename=reportCard" + a + ".pdf";
    x[0] = new Microsoft.Reporting.WebForms.ReportParameter("Name", data.name);  




    RptVr.LocalReport.SetParameters(x);
    string deviceInfo =
     "<DeviceInfo>" +
     "  <OutputFormat>EMF</OutputFormat>" +
     "  <PageWidth>11in</PageWidth>" +
     "  <PageHeight>8.5in</PageHeight>" +
     "  <MarginTop>0in</MarginTop>" +
     "  <MarginLeft>0in</MarginLeft>" +
     "  <MarginRight>0in</MarginRight>" +
     "  <MarginBottom>0in</MarginBottom>" +
     "</DeviceInfo>";

    Byte[] results =  RptVr.LocalReport.Render("PDF", deviceInfo);
 

    Response.ContentType = "Application/pdf";
    Response.AddHeader("content-disposition", fname);
    Response.OutputStream.Write(results, 0, results.Length);




this is working but when i try to loop like below, i know there is something wrong. I tried to generate the report in a loop and get one pdf output file.

C#
var db = Database.Open("dbConnection");
    var data = db.Query("select name from customer_table");            
  
 for(i = 0; i<data.length;i++)
{

    Microsoft.Reporting.WebForms.ReportViewer RptVr = new   Microsoft.Reporting.WebForms.ReportViewer();
    
        RptVr.LocalReport.ReportPath = "~/report/a.rdlc";
    
    RptVr.LocalReport.EnableExternalImages = true;

    Microsoft.Reporting.WebForms.ReportParameter[] x = new Microsoft.Reporting.WebForms.ReportParameter[1];
  
    var fname = "";
    
        fname = "inline; filename=reportCard" + a + ".pdf";
    x[0] = new Microsoft.Reporting.WebForms.ReportParameter("Name", data.name);  




    RptVr.LocalReport.SetParameters(x);
    string deviceInfo =
     "<DeviceInfo>" +
     "  <OutputFormat>EMF</OutputFormat>" +
     "  <PageWidth>11in</PageWidth>" +
     "  <PageHeight>8.5in</PageHeight>" +
     "  <MarginTop>0in</MarginTop>" +
     "  <MarginLeft>0in</MarginLeft>" +
     "  <MarginRight>0in</MarginRight>" +
     "  <MarginBottom>0in</MarginBottom>" +
     "</DeviceInfo>";

    Byte[] results =  RptVr.LocalReport.Render("PDF", deviceInfo);


    Response.ContentType = "Application/pdf";
    Response.AddHeader("content-disposition", fname);
    Response.OutputStream.Write(results, 0, results.Length);
i++;
}


Please help how do i do that.

What I have tried:

I tried to generate reports dynamically one by one in a loop and try to put that in one pdf file
Posted
Updated 20-Dec-16 14:55pm
v2

1 solution

One solution is to create a big report with subreports then print the big report.

So essentially each of you existing report would become a subreport of the main report.

You will have to create one RDLC file for the main report and add each subreport. You might need to "loop" subreport if same subreport can be repeated.

You will have to "send" appropriate parameters to each subreport. And you also have to properly adjust the layout to get the desired final result.

After all, it is a lot of work... I don't have any code as it is not trivial and I do not have access to code I have done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900