Skip to main content

Merge Reports: Specify Page Sequence Manually

  • 6 minutes to read

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

Tip

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

To add document pages from one report to a document created from another report, follow the steps below.

using DevExpress.XtraReports.UI;
// ...
// Create the first report and generate its document.
XtraReport1 report1 = new XtraReport1();
report1.CreateDocument();

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

// Add all pages of the second report to the end of the first report.
report1.ModifyDocument(x => {
    x.AddPages(report2.Pages);
});

// Preview the modified report.

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

using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System;
using System.Drawing;
// ...
XtraReport CreateReport() {
    XtraReport1 report1 = new XtraReport1();
    report1.AfterPrint += Report1_AfterPrint;
    return report1;
}

void Report1_AfterPrint(object sender, EventArgs e) {
    XtraReport2 report2 = new XtraReport2();
    report2.CreateDocument();

    XtraReport report1 = (XtraReport)sender;
    report1.ModifyDocument(x => x.AddPages(report2.Pages));
}

Note

The XtraReport.ModifyDocument method was implemented in v18.1.8.

Limitations

  • The Preview does not support document export in continuous (single file) mode. You can choose one of the following options:

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

  • Page setup is not available in Preview mode.
  • Merged reports do not share bookmarks and tables of contents. The resulting document shows bookmarks of all merged reports in a flat tree. There is no option to create a parent bookmark for each merged report. For more control over bookmarks, use the Subreports technique described in the following topic: Add a Report to the End/Beginning. The SubreportBase.BookmarkParent property allows you to specify the TOC parent node for each report.
  • The main report’s Parameters Panel does not display parameters of the reports whose pages are merged into the main report. If you want to specify parameter values for the merged report, use XRSubreport controls in the main report and bind subreport parameters to the main report’s parameters. Refer to the following topic for an example: Merge Reports: Use Data-Driven Page Sequence.

Tip

Do not destroy 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 decrease memory consumption. These components 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.XtraPrinting.Caching;
using DevExpress.XtraReports.UI;
// ...
// Create the first report and generate its document.
var storage1 = new MemoryDocumentStorage();
var report1 = new XtraReport1();
var cachedReportSource1 = new CachedReportSource(report1, storage1);
cachedReportSource1.CreateDocument();
// Create the second 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 second report to the end of the first report.
// Use either XtraReport.ModifyDocument() or CachedReportSource.ModifyDocument().
report1.ModifyDocument(x => {
    x.InsertPage(1, cachedReportSource2.PrintingSystem.Pages[0]);
});

// Preview the first report using the cachedReportSource1 object.

The code sample below illustrates how to use the ModifyDocument(Action<IDocumentModifier>) method to append pages to a large report.

using DevExpress.XtraPrinting.Caching;
using DevExpress.XtraReports.UI;
// ...
// Create the first report and generate its document.
var storage1 = new MemoryDocumentStorage();
var report1 = new XtraReport1();
var cachedReportSource1 = new CachedReportSource(report1, storage1);
cachedReportSource1.CreateDocument();
// Create the second 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 second report to the end of the first report.
// Use either XtraReport.ModifyDocument() or CachedReportSource.ModifyDocument().
report1.ModifyDocument(x => {
    x.AddPages(cachedReportSource2.PrintingSystem.Pages);
});

// Preview the first report using the cachedReportSource1 object.
See Also