Skip to main content

ReportPrintTool Class

A tool that allows you to publish reports in WinForms applications.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraPrinting.v24.1.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.Printing

Declaration

public class ReportPrintTool :
    PrintTool,
    IReportPrintTool,
    IReportTool,
    IDisposable

Remarks

Use the ReportPrintTool class to show a report document in a Print Preview form or immediately send a report to a printer.

Create an object of this class and pass the report to the object’s constructor. Use the print tool’s Report property to access a report assigned to a ReportPrintTool object. To publish reports in a Web reporting application, use the Web Document Viewer control.

Create the ReportPrintTool instance.

Pass the report’s instance to the ReportPrintTool constructor as a parameter. Use one of the ReportPrintTool‘s methods to print the associated report:

  • The PrintToolBase.Print method sends a document to a printer (the system’s default or a specific printer) using default printing settings.

    You see an exception when a printer with the specified name is not found.

    In Print Preview, this method corresponds to the Quick Print command.

  • The PrintTool.PrintDialog method raises the Print dialog, where an end-user can select a printer and specify other print options before printing the document.

    In Print Preview, this method corresponds to the Print command.

The following code illustrates how to use these methods to print a report in a Windows Forms application:

using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
// ...

private void button1_Click(object sender, EventArgs e) {
    XtraReport1 report = new XtraReport1();
    ReportPrintTool printTool = new ReportPrintTool(report);
    // Invoke the Print dialog.
    printTool.PrintDialog();
    // Send the report to the default printer.
    printTool.Print();
    // Send the report to the specified printer.
    printTool.Print("myPrinter");
}

Tip

Call of the Print and PrintDialog method calls the XtraReport.CreateDocument method internally to create a report document in case it does not exist.

Use the CachedReportSource component to print reports that include a huge amount of data. This component stores pages in a file system or database when the document is generated and thus allows you to avoid issues related to memory consumption. Assign the report that you want to print to a CachedReportSource object and pass this object to ReportPrintTool as a constructor parameter as shown in the example below:

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

ReportPrintTool printTool = new ReportPrintTool(cachedReportSource);

Refer to the following topics for more details:

Enable DirectX Rendering

The GDI+ library is the default rendering engine for Print Preview elements. If a preview displays a document that contains many pages, this engine might render this document slowly. To boost rendering performance, you can switch to the DirectX rendering engine. The following code sample demonstrates how to do it for the Ribbon Print Preview:

using DevExpress.XtraReports.UI;
// ...
var printTool = new ReportPrintTool(new XtraReport1());
printTool.PreviewRibbonForm.PrintControl.UseDirectXPaint = DevExpress.Utils.DefaultBoolean.True;
printTool.ShowRibbonPreviewDialog();

You can also set the EnableSmoothScrolling property to True to allow for more smooth page scrolling in DirectX mode.

using DevExpress.XtraReports.UI;
// ...
printTool.PreviewRibbonForm.PrintControl.UseDirectXPaint = DevExpress.Utils.DefaultBoolean.True;
printTool.PreviewRibbonForm.PrintControl.EnableSmoothScrolling = DevExpress.Utils.DefaultBoolean.True;

Note that smooth scrolling might require more application resources to render the pages.

The following limitations apply to the Print Preview when it uses DirectX rendering:

  • The Cached Report Source component is not supported.
  • The XRRichText control is rendered as an image. The default GDI+ library is used to render this control.
  • String sizes in a document might be greater compared with the case when the GDI+ library is used to render the document.

Inheritance

See Also