Skip to main content Skip to footer

Combining Reports

With ActiveReports, you can combine multiple reports into one. How you do it depends on the type of report. Let's take a look at the ways you can combine each type of report.

Section Reports

In Section reports, there are several ways to create a report that is composed of other reports.

  1. Add or insert report pages
  2. Overlay report pages
  3. Combine pages from saved documents

Here is how you do it.

Add or Insert Report Pages

In Section reports, the Document.Pages property (in the PagesCollection class) stores the results of report generation for each page when you run a report. You can add, insert, copy, and remove generated pages using methods in the PagesCollection class such as Add, AddRange, CopyTo, Insert, InsertRange, Remove. There are many more methods in this class that allow you to manipulate the pages.

'Visual Basic  

' Run each report.  
rpt1.Run(False)  
rpt2.Run(False)  

' Add the pages of rpt2 after rpt1.  
For i As Integer = 0 To rpt2.Document.Pages.Count - 1  
  rpt1.Document.Pages.Add(rpt2.Document.Pages(i).Clone())  
Next  

'' The following code gets the same results.  
'rpt1.Document.Pages.AddRange(rpt2.Document.Pages.Clone())
//C#  

// Run each report.  
rpt1.Run(false);  
rpt2.Run(false);  

// Add the pages of rpt2 after rpt1.  
for (int i = 0; i < rpt2.Document.Pages.Count; i++)  
{  
  rpt1.Document.Pages.Add(rpt2.Document.Pages[i].Clone());  
}  
//// The following code gets the same results.  
//rpt1.Document.Pages.AddRange(  
//  (GrapeCity.ActiveReports.Document.Section.PagesCollection)  
//    rpt2.Document.Pages.Clone());

Once combined, you can display the pages in a viewer, export them, or print them. You can even set the index at which to insert pages, set up print layouts that specify the front and back pages in duplex printing, and print reports in reverse order (last page to first). Note: You can only combine Section reports with other Section reports.

Overlay Report Pages

In Section reports, you can also superimpose one page over another using the Overlay method of the page. Note: To overlay pages as in the image above, adjust the Height of the sections in Report A and Report B in the Properties window.

'Visual Basic  

' Run each report.  
rpt1.Run(False)  
rpt2.Run(False)  

' Overlay the first page of rpt2 onto each page of rpt1.  
For i As Integer = 0 To rpt1.Document.Pages.Count - 1  
  rpt1.Document.Pages(i).Overlay(rpt2.Document.Pages(0).Clone())  
Next
//C#  

// Run each report.  
rpt1.Run(false);  
rpt2.Run(false);  

// Overlay the first page of rpt2 onto each page of rpt1.  
for (int i = 0; i < rpt1.Document.Pages.Count; i++)  
{  
  rpt1.Document.Pages[i].Overlay(  
    (GrapeCity.ActiveReports.Document.Section.Page)  
      rpt2.Document.Pages[0].Clone());  
}

Once combined, you can display the pages in a viewer, export them, or print them.

Combine Pages from Saved Documents

The ActiveReports Document API for Section reports allows you to extract pages from report documents saved to *.rdf format, even ones pulled from databases as BLOBs. This allows you to manipulate pages from snapshots of historic data and combine them with current data. The possibilities are endless!

 ' Visual Basic  
    ' Specify paths to reports that were saved to RDF format.  
    Dim invoiceRdf As String  
    invoiceRdf = Application.StartupPath.ToString + "..\\..\\..\\Invoice.rdf"  
    Dim letterRdf As String  
    letterRdf = Application.StartupPath.ToString + "..\\..\\..\\Letter.rdf"  
    ' Create a section report object to hold the pages of the final merged report.  
    Dim merge As New GrapeCity.ActiveReports.SectionReport  
    ' Create a section report document object in which to load pages from the RDFs.  
    Dim fRdf As New GrapeCity.ActiveReports.Document.SectionDocument  

    ' Load the invoice report into the document object.  
    fRdf.Load(invoiceRdf)  
    ' Add the pages of the invoice report to the merge report.  
    merge.Document.Pages.AddRange(fRdf.Pages)  
    ' Clear the pages from the document object.  
    fRdf.Pages.Clear()  
    ' Load the letter report into the document object.  
    fRdf.Load(letterRdf)  
    ' After each invoice page, insert a letter page.  
    For i As Integer = 0 To fRdf.Pages.Count - 1  
        merge.Document.Pages.Insert(i + 1, fRdf.Pages(i))  
        i = i + 1  
    Next
 // C#  
        // Specify paths to reports that were saved to RDF format.  
        string invoiceRdf = null;  
        invoiceRdf = Application.StartupPath.ToString() + "..\\\..\\\..\\\Invoice.rdf";  
        string letterRdf = null;  
        letterRdf = Application.StartupPath.ToString() + "..\\\..\\\..\\\Letter.rdf";  

        // Create a section report object to hold the pages of the final merged report.  
        GrapeCity.ActiveReports.SectionReport merge = new GrapeCity.ActiveReports.SectionReport();  
        // Create a section report document object in which to load pages from the RDFs.  
        GrapeCity.ActiveReports.Document.SectionDocument fRdf = new GrapeCity.ActiveReports.Document.SectionDocument();  

        // Load the invoice report into the document object.  
        fRdf.Load(invoiceRdf);  
        // Add the pages of the invoice report to the merge report.  
        merge.Document.Pages.AddRange(fRdf.Pages);  
        // Clear the pages from the document object.  
        fRdf.Pages.Clear();  
        // Load the letter report into the document object.  
        fRdf.Load(letterRdf);  
        // After each invoice page, insert a letter page.  
        for (int i = 0; i < = fRdf.Pages.Count - 1; i++)  
        {  
            merge.Document.Pages.Insert(i + 1, fRdf.Pages[i]);  
            i = i + 1;  
        }

Note: In order to run the code above, you need to add a reference to the PDF Export, and add using or imports directives for each class that is referenced in the code.

Page and RDL Reports

In Page and RDL reports, there is no function provided to combine reports at the document level, but there are a couple of alternatives.

  • Merge exported PDF files
  • Use multiple page layouts (Page reports only)

Merge Exported PDF Files

Using the PDF rendering extension API, you can add PDF file contents before and after your report during export.

 'Visual Basic  
    ' Create a new page report.  
    Dim _reportDef As New PageReport(New FileInfo("..\\..\\NWindTable.rdlx"))  
    Dim reportDocument As New PageDocument(_reportDef)  

    ' Set up the PDF file names and paths.    
    Dim exportFileBefore As String = Application.StartupPath + "/../../one.pdf"  
    Dim exportFileAfter As String = Application.StartupPath + "/../../three.pdf"  
    Dim exportFileRdlx As String = "merge.pagereports.pdf"  

    ' Set up PDF files to merge into the export.  
    Dim settings As Export.Pdf.Page.Settings = New GrapeCity.ActiveReports.Export.Pdf.Page.Settings()  
    settings.DocumentToAddBeforeReport = exportFileBefore  
    settings.DocumentToAddAfterReport = exportFileAfter  

    Dim myFile1 As New FileInfo(exportFileRdlx)  

    ' Export the report to PDF and merge the other PDF files into it.    
    Dim pdfRenderingExtension As New PdfRenderingExtension()  
    Dim _outputProvider As New FileStreamProvider(myFile1.Directory, myFile1.Name)  
    reportDocument.Render(pdfRenderingExtension, _outputProvider, settings)
 // C#  
    // Create a new page report.  
    PageReport _reportDef = new PageReport(new FileInfo(@"..\\..\\NWindTable.rdlx"));  
    PageDocument reportDocument = new PageDocument(_reportDef);  

    // Set up the PDF file names and paths.    
    string exportFileBefore = Application.StartupPath + @"/../../one.pdf";  
    string exportFileAfter = Application.StartupPath + @"/../../three.pdf";  
    string exportFileRdlx = "merge.pagereports.pdf";  

    // Set up PDF files to merge into the export.  
    settings = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();  
    settings.DocumentToAddBeforeReport = exportFileBefore;   
    settings.DocumentToAddAfterReport = exportFileAfter;   

    FileInfo myFile1 = new FileInfo(exportFileRdlx);  

    // Export the report to PDF and merge the other PDF files into it.    
    PdfRenderingExtension pdfRenderingExtension = new PdfRenderingExtension();  
    FileStreamProvider _outputProvider = new FileStreamProvider(myFile1.Directory, myFile1.Name);  
    reportDocument.Render(pdfRenderingExtension, _outputProvider, settings);

For more information on other settings you can use with the PDF rendering extension, see the Settings class members in the Class Library, and the User Guide topic on Rendering to PDF.

Use Multiple Page Layouts

It isn't the same as combining reports, but with Page reports, you can use a different page layout for subsequent pages when you output data into data regions that grow, like a Table or List control, and the data overflows the first page. Image of a page report with multiple layouts For more information and samples of multiple layout reports, see the following topics in our User Guide. Page Tabs | Page Report | OverflowPlaceHolder | Reports Gallery | Overflow Data in Multiple Pages

MESCIUS inc.

comments powered by Disqus