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

XtraReport.Pages Property

Gets a collection of pages generated for this report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v17.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[Browsable(false)]
public PageList Pages { get; }

Property Value

Type Description
PageList

A PageList object, specifying a collection of pages.

Remarks

After calling the XtraReport.CreateDocument method (or after calling the PrintTool.ShowPreview or PrintTool.ShowPreviewDialog methods for the first time), you can access all pages of the generated Document using the Pages property.

The PageList object, which is the returned collection of pages, exposes methods that allow you to reorder and remove pages, as well as to add and insert pages from other reports (see Merging Reports for details). You can also add an empty page using the PrintingSystemBase.CreatePage method of the report’s XtraReport.PrintingSystem.

Use the PrintingSystemBase.ContinuousPageNumbering property to specify whether to update the page numbers after customizing the collection of pages or preserve the page numbers from the original document(s).

Example

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();
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the Pages property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also