Invoke a Default Document Preview

This topic describes how to display a report in the Document Preview window that is supplied with DevExpress Reporting for WPF applications.

Essential Methods

Use the PrintHelper class's methods to display a report in one of the default Document Preview windows:

Note

Add the DevExpress.Xpf.Printing.v18.2.dll and DevExpress.Xpf.Core.v18.2.dll assemblies to the References list of your project to use this class. Refer to the Application Deployment topic for a full list of the libraries required to load a Document Preview.

Preview Light-Weight Reports

Call one of the PrintHelper's methods detailed above passing a report instance as a parameter to show a Document Preview window with the report.

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

using DevExpress.Xpf.Printing;
// ...

private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) {
    // Invoke the Ribbon Print Preview window 
    // and load the report document into it.
    PrintHelper.ShowRibbonPrintPreview(this, new XtraReport1());

    // Invoke the Ribbon Print Preview window modally.
    PrintHelper.ShowRibbonPrintPreviewDialog(this, new XtraReport1());

    // Invoke the standard Print Preview window 
    // and load the report document into it.
    PrintHelper.ShowPrintPreview(this, new XtraReport1());

    // Invoke the standard Print Preview window modally.
    PrintHelper.ShowPrintPreviewDialog(this, new XtraReport1());
}
Tip

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

The Document Preview displays pages 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.

Call one of the PrintHelper's methods detailed above passing a CachedReportSource instance as a parameter to show a Document Preview window with the associated report.

using DevExpress.Xpf.Printing;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...

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

    // Invoke the Ribbon Print Preview window 
    // and load the report document into it.
    PrintHelper.ShowRibbonPrintPreview(this, cachedReportSource);

    // Invoke the Ribbon Print Preview window modally.
    PrintHelper.ShowRibbonPrintPreviewDialog(this, cachedReportSource);

    // Invoke the standard Print Preview window 
    // and load the report document into it.
    PrintHelper.ShowPrintPreview(this, cachedReportSource);

    // Invoke the standard Print Preview window modally.
    PrintHelper.ShowPrintPreviewDialog(this, cachedReportSource);
}
Tip

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

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

See Also