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

Invoke the Built-in Print Preview Form

  • 4 minutes to read

Note

An active license for the DevExpress Reporting Subscription is required to use the API in this tutorial.

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

ReportPrintTool Methods

Create the ReportPrintTool class instance and use any of the following methods to invoke a Print Preview form and view a report in a WinForms application:

You can specify the default or custom look and feel settings as the method parameter.

Preview Light-Weight Reports

Pass the report instance to the ReportPrintTool constructor as a parameter. Use one of the ShowPreview methods to invoke the Print Preview form.

The following code calls different ReportPrintTool methods to preview a report:

using DevExpress.XtraReports.UI;
using DevExpress.LookAndFeel;
// ...
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);

The viewer automatically starts the document creation process and displays document pages as soon as they are ready.

Preview Large Reports

Use the CachedReportSource component to preview a large report that contains over 10,000 pages. The CachedReportSource component stores generated pages in the file system, database, or compressed memory streams. The dedicated storage allows you to overcome memory allocation limitations and avoid the OutOfMemory exception. The size of a document is limited only by the available storage space. A substantial increase in the number of pages does not lead to a significant increase in memory consumption.

The CachedReportSource may decrease overall performance because of the time required to store a page and retrieve it from the storage. You should test your application and decide whether it can benefit from the CachedReportSource component.

The following code creates a CachedReportSource instance that uses the MemoryDocumentStorage storage type for the specified report.

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

Instead of memory storage, you can use the FileDocumentStorage, or DbDocumentStorage storage types.

Use the ReportPrintTool constructor with the CachedReportSource instance passed as a parameter, and call one of the ShowPreview methods to preview a report:

using DevExpress.XtraReports.UI;
using DevExpress.LookAndFeel;
using DevExpress.XtraPrinting.Caching;
// ...
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);

The viewer automatically starts the document creation process and displays document pages as soon as they are ready. You should not call the CachedReportSource.CreateDocumentAsync method before creating the ReportPrintTool instance.

Display an Empty Print Preview

Create the ReportPrintTool instance for an empty report (a report that does not contain report controls) to invoke an empty Print Preview form without the document:

using DevExpress.XtraReports.UI;
// ...
ReportPrintTool printTool = new ReportPrintTool(new XtraReport());
printTool.ShowRibbonPreview();

print-preview-empty-document