Print and Export Reports without a Preview
- 4 minutes to read
Users can print or export a report when it is displayed in the Document Viewer. As an alternative, you can print and export reports without having to display them first, as described in this topic.
Create a Report
You can add a report to your application in Visual Studio. See the Create a Report in Visual Studio topic for information on how to do this.
Reports can also be created in application code. See the XtraReport class description for more information.
Print a Report
Use the PrintToolBase.Print method to print a report, as shown in the following code sample:
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System.Drawing.Printing;
// ...
// Create a simple report in code.
XtraReport report = new XtraReport() {
Bands = {
new DetailBand() {
Name = "DetailBand",
Controls = {
new XRLabel() {
Text = "Simple Report"
}
}
}
}
};
// Print the report.
report.CreateDocument();
PrintToolBase tool = new PrintToolBase(report.PrintingSystem);
tool.Print();
Note
In a server-side application, (for instance, in a web application), the code above sends a report to the default server-side printer.
The Print Reports section describes how to print reports on different platforms.
Export a Report
The XtraReport class exposes methods to export a report to different file formats. Call these methods to export a report from an application that does not have a GUI.
using DevExpress.XtraReports.UI;
// ...
// Create a simple report in code.
XtraReport report = new XtraReport() {
Bands = {
new DetailBand() {
Name = "DetailBand",
Controls = {
new XRLabel() {
Text = "Simple Report"
}
}
}
}
};
// Export the report to PDF.
//Save the export file to the user's Downloads folder.
report.ExportToPdf(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) +
@"\Downloads\" + report.Name + ".pdf"
);
Review the following topic for information on how to export a report to different file formats: Document Export Overview.
Print and Export in Web Applications
Libraries Required to Print and Export Reports
Add the following libraries to your application to print and export reports. Alternatively, you can add the DevExpress.Reporting.Core NuGet package that includes these core libraries.
Assembly | Description |
---|---|
DevExpress.Data.v24.2.dll | Contains base classes for DevExpress controls. |
DevExpress.Drawing.v24.2.dll | Implements the basic graphics functionality. |
DevExpress.Printing.v24.2.Core.dll | Implements basic DevExpress printing features. |
DevExpress.XtraReports.v24.2.dll | Contains the XtraReport class. |
Optional Assembly | Description |
---|---|
DevExpress.Charts.v24.2.Core.dll | Required if a report contains XRChart controls. |
DevExpress.CodeParser.v24.2.dll | Required to process report scripts. |
DevExpress.Data.Desktop.v20.1.dll | Contains base classes for DevExpress controls in .NET Framework and .NET. Includes classes that bind data, print, and export content. This library is required if you use the WinControlContainer class to print WinForms controls. |
DevExpress.DataAccess.v24.2.dll | Required when a report is bound to an SQL, Entity Framework, XPO, Excel, JSON, Object, or Federation data source. |
DevExpress.Office.v24.2.Core.dll | Required to export reports to DOCX, or when a report contains XRRichText controls. |
DevExpress.Pdf.v24.2.Core.dll | Required to export reports to PDF. |
DevExpress.Pdf.v20.1.Drawing.dll | Implements PDF-related features. Required to preview reports that are merged with PDF content. |
DevExpress.PivotGrid.v24.2.Core.dll | Required if a report contains XRPivotGrid or XRCrossTab controls. |
DevExpress.RichEdit.v24.2.Core.dll | Required to export reports to DOCX, or when a report contains at least one XRRichText control. |
DevExpress.RichEdit.v24.2.Export.dll | Required to export reports to DOCX. |
DevExpress.Sparkline.v24.2.Core.dll | Required if a report contains XRSparkline controls. |
DevExpress.Xpo.v24.2.dll | Required if a report is bound to an SQL, XPO, or Entity Framework data source. |
DevExpress.XtraCharts.v24.2.dll | Required if a report contains XRChart controls. |