Skip to main content
A newer version of this page is available. .

Merging Reports

  • 5 minutes to read

You can merge pages from different report documents to create a single combined document. This enables you to print and export merged pages as a single document while preserving the original reports’ page settings and orientation.

report-merging

This topic consists of the following sections:

Document Merging Overview

Merging different reports helps you to solve the following tasks:

  • Send multiple reports to a printer as a single print job.
  • Export multiple reports to a single file (such as PDF or DOCX).
  • Create a report with pages having different paper kinds.

Calling the XtraReport.CreateDocument method generates a paginated document for a particular report, after which you can access its pages using the XtraReport.Pages property. Before merging different reports, you need to create their documents and manage their collections of pages.

Enable the PrintingSystemBase.ContinuousPageNumbering property to update page numbers after changing a report’s collection of pages, or disable it to preserve the original page numbers.

Limitations

The following limitations apply to merged documents in Print Preview:

  • Continuous (single file) document export is not supported, and the corresponding option is hidden in the GUI.
  • Any actions that require rebuilding the document are not supported, including the drill-down functionality, document scaling, interactive margins, page orientation and page size settings.
  • Report parameters are not supported in most cases.

Code Examples

This example demonstrates how to access and customize a collection of document pages (XtraReport.Pages).

Tip

Do not dispose of the merged documents before publishing the resulting document (the resulting document does not create a “deep copy” of merged documents).

The following code appends an entire document to the end of another document:

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.Pages.AddRange(report2.Pages);

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

    // Show the Print Preview form (in a WinForms application).
    ReportPrintTool printTool = new ReportPrintTool(report1);
    printTool.ShowPreviewDialog();
}

Tip

Composite report documents created from multiple merged documents do not support continuous (single file) export. An attempt to export a composite document to a single file only exports its first merged document.

As a workaround, you can use subreports to display multiple reports in a single document, or you can export individual documents to separate files and then manually combine them into a single file.

The following code combines two documents into one document:

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

private void MergeTwoReports() {
    // 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();

    // Merge the pages of two reports.
    int minPageCount = Math.Min(report1.Pages.Count, report2.Pages.Count);
    for (int i = 0; i < minPageCount; i++) {
        report1.Pages.Insert(i * 2 + 1, report2.Pages[i]);
    }
    if (report2.Pages.Count != minPageCount) {
        for (int i = minPageCount; i < report2.Pages.Count; i++) {
            report1.Pages.Add(report2.Pages[i]);
        }
    }

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

    // Show the Print Preview form (in a WinForms application).
    ReportPrintTool printTool = new ReportPrintTool(report1);
    printTool.ShowPreviewDialog();
}

The following code reorders document pages to produce a booklet (first page, last page, second page, last but one, third page, etc.):

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

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

    // Preserve the original page numbers on all pages.
    report1.PrintingSystem.ContinuousPageNumbering = false;

    // Create a booklet.
    int centerPageIndex = Convert.ToInt32((report1.Pages.Count - 1) / 2);
    for (int i = 0; i < centerPageIndex; i++) {
        report1.Pages.Insert(i * 2 + 1, report1.Pages[report1.Pages.Count - 1]);
    }

    // Show the Print Preview form (in a WinForms application).
    ReportPrintTool printTool = new ReportPrintTool(report1);
    printTool.ShowPreviewDialog();
}
See Also