Invoke a Default Document Preview
- 4 minutes to read
This topic describes how to display a report in the Document Preview window that is supplied with DevExpress Reporting for WPF applications.
#Basic Methods
Use the PrintHelper class methods to display a report in one of the default Document Preview windows.
Note
Do the following to use the Print
- .NET Framework – add the DevExpress.
Xpf. 24.Printing. v 2 .dll and DevExpress.Xpf. 24.Core. v 2 .dll assemblies to the application References list. - .NET – add the DevExpress.
Wpf. NuReporting Get package to your application.
Refer to the WPF Reporting Application Deployment topic for a full list of libraries required to load a Document Preview.
The PrintHelper.ShowRibbonPrintPreview and PrintHelper.ShowRibbonPrintPreviewDialog methods show a window with a Ribbon toolbar.
The PrintHelper.ShowPrintPreview and PrintHelper.ShowPrintPreviewDialog methods invoke a window with a standard toolbar.
#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 Xtra
The Document Preview displays pages as soon as they are generated.
#Preview Large Reports
Use the CachedReportSource component to preview reports that include a large 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 Cached
When a Document Preview is associated with a Cached