The requested page is not available for the requested platform. You are viewing the content for Default platform.

Merge Reports: Specify Page Sequence Manually

  • 5 min to read

This topic describes how to generate two reports and merge them on the page-by-page basis.

Tip

When you merge reports in eXpressApp Framework applications, follow the instructions given in the How to: Merge the Pages of Two Reports topic.

using DevExpress.XtraReports.UI;
// ...

private void CombineTwoReports() {
    // Create the 1st report and generate its document.
    XtraReport1 report1 = new XtraReport1();
    report1.CreateDocument();

    // Create the 2nd report and generate its document.
    XtraReport2 report2 = new XtraReport2();
    report2.CreateDocument();

    // Add all pages of the 2nd report to the end of the 1st report.
    report1.ModifyDocument(x => {
        x.AddPages(report2.Pages);
    });

    // Reset all page numbers in the resulting document.
    report1.PrintingSystem.ContinuousPageNumbering = true;

    // Preview the modified report.
    //...
}

To add pages to a report when it is generated, handle the report's XRControl.AfterPrint event.

using System;
// ...

private void XtraReport1_AfterPrint(object sender, EventArgs e) {   
    //Create the 2nd report and generate its document.
    XtraReport2 report2 = new XtraReport2();
    report2.CreateDocument();

    // Enable this property to maintain continuous page numbering
    PrintingSystem.ContinuousPageNumbering = true;

    // Add all pages of the 2nd report to the end of the 1st report.
    ModifyDocument(x => {
        x.AddPages(report2.Pages);
    });        
}
Note

The XtraReport.ModifyDocument method was implemented in version 18.1.8.

Limitations

  • The Preview does not support document export in continuous (single file) mode. As a workaround, you can use either of the following:

    • Use subreports to display multiple reports in a single document.
    • Export individual documents to different files and then combine them into a single file.
  • Interactive features are not available (for instance, the drill-down functionality, sorting, report parameters input).

  • Page setup is not available in Preview mode.
  • The combined reports do not share bookmarks and tables of contents. These items remain specific to the original reports.
Tip

Do not destroy the source documents before you publish the resulting document (the resulting document does not create a "deep copy" of the source documents).

Merge Large Reports

When you display, print or export documents that contain thousands of pages, use the CachedReportSource/CachedReportSourceWeb components to avoid memory consumption-related issues. These component generate a report document and cache each generated page in the specified storage - memory, file or database.

The code sample below illustrates how to add a title page to a large report.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ... 
private void CombineTwoReports() {
    // Create the 1st report and store its pages in memory.
    var mainReportStorage = new MemoryDocumentStorage();
    var mainReport = new XtraReport1();
    var cachedMainReportSource = new CachedReportSource(mainReport, mainReportStorage);
    cachedMainReportSource.CreateDocument();

    // Create the 2nd report and store its pages in memory.
    var titleReportStorage = new MemoryDocumentStorage();
    var titleReport= new XtraReport2();
    var cachedTitleReportSource = new CachedReportSource(titleReport, titleReportStorage);
    cachedTitleReportSource.CreateDocument();

    // Insert pages from the 2nd report into the 1st report.
    mainReport.ModifyDocument(x => {
        x.InsertPage(0, cachedTitleReportSource.PrintingSystem.Pages[0]);
    }
} 

The code sample below illustrates how to use the ModifyDocument(Action<IDocumentModifier>) method to append a report's pages to a large 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.
    report1.ModifyDocument(x => {
        x.AddPages(cachedReportSource2.PrintingSystem.Pages);
    };

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