Invoke a Default Print Preview Form

Note

You need a Reporting subscription to use the API described in this tutorial.

This topic describes how to display a report in the Print Preview form that is supplied with DevExpress Reporting for WinForms applications.

Essential Methods

Create the ReportPrintTool class's instance and use any of the following methods to load a report in a default Print Preview form in a WinForms application:

Each of these methods has overloads to invoke the Preview form with either the default or custom look and feel settings applied.

Preview Light-Weight Reports

Bind a Print Preview form to a report by passing the report's instance to the ReportPrintTool object' constructor as a parameter. Use one of the ReportPrintTool's methods detailed above to invoke the Print Preview form with the displayed report.

The following code illustrates how to call these methods in the main application form's Load event handler:

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

private void Form_Load(object sender, System.EventArgs e) {
    ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());

    // Invoke the Ribbon Print Preview form  
    // and load the report document into it. 
    printTool.ShowRibbonPreview();

    // Invoke the Ribbon Print Preview form modally 
    // with the specified look and feel settings. 
    printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default);

    // Invoke the Print Preview form  
    // and load the report document into it. 
    printTool.ShowPreview();

    // Invoke the Print Preview form modally 
    // with the specified look and feel settings. 
    printTool.ShowPreviewDialog(UserLookAndFeel.Default);
}
Tip

Calling any of these methods starts generating document pages by calling the XtraReport.CreateDocument method internally if they are not generated yet.

Pages are loaded to the Print Preview as soon as they are generated.

Preview Large Reports

Use the CachedReportSource component to preview reports that include a huge 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.

Create a CachedReportSource instance specifying a report to be previewed and a storage to cache the report document.

using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
//...
    var storage = new MemoryDocumentStorage();
    var report = new XtraReport1();
    var cachedReportSource = new CachedReportSource(report, storage); 

The MemoryDocumentStorage object used in this code stores a document in memory in a compact way. You can use the FileDocumentStorage, DbDocumentStorage or implement a custom storage instead.

Bind a Print Preview form to a large report by passing a CachedReportSource instance associated with this report to the ReportPrintTool object' constructor as a parameter. Use one of the ReportPrintTool's methods detailed above to invoke the Print Preview form with the report displayed.

using DevExpress.XtraReports.UI;
using DevExpress.LookAndFeel;
using DevExpress.XtraPrinting.Caching;
// ...

private void Form_Load(object sender, System.EventArgs e) {
    var storage = new MemoryDocumentStorage();
    var report = new XtraReport1();
    var cachedReportSource = new CachedReportSource(report, storage);

    ReportPrintTool printTool = new ReportPrintTool(cachedReportSource);

    // Invoke the Ribbon Print Preview form  
    // and load the report document into it. 
    printTool.ShowRibbonPreview();

    // Invoke the Ribbon Print Preview form modally 
    // with the specified look and feel settings. 
    printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default);

    // Invoke the Print Preview form  
    // and load the report document into it. 
    printTool.ShowPreview();

    // Invoke the Print Preview form modally 
    // with the specified look and feel settings. 
    printTool.ShowPreviewDialog(UserLookAndFeel.Default);
}
Tip

Calling any of these methods starts generating document pages by calling the CachedReportSource.CreateDocumentAsync method internally if they are not generated yet.

When a Print Preview is associated with a CachedReportSource component, only visible pages are stored in memory.

Display an Empty Print Preview

Calling the ReportPrintTool object' methods for an empty report (containing no controls on any of its bands) does not create a document and loads an empty Print Preview form:

print-preview-empty-document