ActiveReports and Multi-report Reports
After a post to DataDynamic’s website about needing to run the SAME report multiple times (in a loop), then combining it into a single PDF, I was told that each had to be a separate report… and never heard back from their technical staff after that.
So, after a couple weeks away from it, I decided to tackle it again this morning.
1 three-page, logical report, 20 “subjects”, aka 60 pages that spools into a single PDF.
The gotcha? You can’t Insert a report into a report, you must open it, spool each page of the report into the “master report,” close it, go to the next, rinse and repeat.
So, here’s the code… previously, you’d have an IList<int> of your PrimaryKeys, or whatever you’re looping through, a System.IO.Path.GetTempFileName that would generate a random file and name (then renamed the .tmp to .pdf).You COULD pregen a DataTable rather than SQL, but.. yeah. Next revision.🙂
public void RunClass(List<int> primaryKey, string filepath, string connString)
// Generate your pdfExporting object.
DataDynamics.ActiveReports.Export.Pdf.PdfExport pdfDoc = new DataDynamics.ActiveReports.Export.Pdf.PdfExport();
// Generate the single report.
Reporting.Reports.IndividualReport rpt = new Reporting.Reports.IndividualReport();
// Generate the “master report” that you’ll insert each single report into.
Reporting.Reports.AllReports crpt = new Reporting.Reports.AllReports();
for (int i = 0; i < primaryKey.Count; i++)
string sql = “select * from database where primaryKey = ‘” + primaryKey[i] + “‘”;
rpt.DataSource = new DataDynamics.ActiveReports.DataSources.OleDbDataSource();
((DataDynamics.ActiveReports.DataSources.OleDbDataSource).rpt.DataSource).ConnectionString = connString;
((DataDynamics.ActiveReports.DataSources.OleDbDataSource).rpt.DataSource).SQL = sql;
// run the individual report
foreach (DataDynamics.ActiveReports.Document.Page p in rpt.Document.Pages)
// insert each report page into the master report.
// generate the PDF of the master report.
From here, you would Reponse.Write the PDF back to the browser (if web) or your filepath would be a specified path (if a console application).
Hope this helps someone… something so simple… bleh.