Merge Large Reports

Use the CachedReportSource/CachedReportSourceWeb component to merge reports that include a large amount of data. This component allows you to avoid memory consumption-related issues by storing pages in a file system or database during document generation.

Note

There are certain limitations when merging reports.

Create a report document using the CachedReportSource component's CreateDocument()/CreateDocumentAsync() method. Access the generated document's pages using the CachedReportSource component's PrintingSystem. Put pages in a specific order using the CachedReportSource component's ModifyDocument(Action<IDocumentModifier>) method. The following code demonstrates how to add a report's title page to the beginning of another report.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ... 
private void CombineTwoReports() {
    var mainReportStorage = new MemoryDocumentStorage();
    var mainReport = new XtraReport1();
    var cachedMainReportSource = new CachedReportSource(mainReport, mainReportStorage);
    cachedMainReportSource.CreateDocument();

    var titleReportStorage = new MemoryDocumentStorage();
    var titleReport= new XtraReport2();
    var cachedTitleReportSource = new CachedReportSource(titleReport, titleReportStorage);
    cachedTitleReportSource.CreateDocument();

    cachedMainReportSource.ModifyDocument(x => {
        x.InsertPage(0, cachedTitleReportSource.PrintingSystem.Pages[0]);
    }
} 

The following code demonstrates how to use the ModifyDocument(Action<IDocumentModifier>) method to add a report's pages to the end of another report.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void CombineTwoReports() {
    // Create the 1st report and generate its document.    
    var storage1 = new MemoryDocumentStorage();
    var report1 = new XtraReport1();
    var cachedReportSource1 = new CachedReportSource(report1, storage1);
    cachedReportSource1.CreateDocument();
    // Create the 2nd report and generate its document.
    var storage2 = new MemoryDocumentStorage();
    var report2 = new XtraReport2();
    var cachedReportSource2 = new CachedReportSource(report2, storage2);
    cachedReportSource2.CreateDocument();

    // Add all pages of the 2nd report to the end of the 1st report.
    cachedReportSource1.ModifyDocument(x => {
    for (int i = 0; i < cachedReportSource2.PrintingSystem.PageCount; i++) {
        x.InsertPage(x.PageCount, cachedReportSource2.PrintingSystem.Pages[i]);
    };

    // Preview the 1st report using the cachedReportSource1 object
    // ...
}