Skip to main content

ReportPrintTool Class

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

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraPrinting.v23.2.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.

The example below illustrates how to define a document scale factor in the Print Preview.

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

private void button1_Click(object sender, EventArgs e) {
    ReportPrintTool printTool = new ReportPrintTool(new XtraReport1());
    printTool.PreviewForm.Load += new EventHandler(PreviewForm_Load);
    printTool.ShowPreviewDialog();
}

void PreviewForm_Load(object sender, EventArgs e) {
    PrintPreviewFormEx frm = (PrintPreviewFormEx)sender;
    frm.PrintingSystem.ExecCommand(PrintingSystemCommand.Scale, new object[] { 0.7f });
}

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