Export to Image
- 5 minutes to read
This document describes how to export a report document to Image format.
You can export a report from the Report Designer’s Preview and the Document Viewer on all supported platforms (WinForms, WPF, ASP.NET Web Forms, ASP.NET MVC, and ASP.NET Core). To do this, expand the Export Document drop-down list and select Image File. Specify export options in the invoked dialog, and click OK.
To export a report document to Image format in code, use one of the following approaches:
Export a Report
Call an XtraReport.ExportToImage overloaded method to export a report. To export a report asynchronously in a separate task, call an XtraReport.ExportToImageAsync overloaded method instead. To specify export options, create a ImageExportOptions class instance and pass this instance to the invoked method, or use XtraReport‘s ExportOptions.Image property.
using System;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
XtraReport report = new XtraReport() {
Name = "HelloWorld",
Bands = {
new DetailBand(){
Controls={
new XRLabel(){
Text="Hello World!"
}
}
}
}
};
// imageExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
string imageExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".image";
// Specify export options to export the report.
// Uncomment the lines below to specify export options in an ImageExportOptions class instance.
// ImageExportOptions ImageExportOptions = new ImageExportOptions();
// ImageExportOptions.ExportMode = ImageExportMode.SingleFile;
// report.ExportToImage(imageExportFile, ImageExportOptions);
// Comment the lines below if you specified export options in an ImageExportOptions class instance above.
report.ExportOptions.Image.ExportMode = ImageExportMode.SingleFile;
report.ExportToImage(imageExportFile);
Export a Document
Call a PrintingSystem.ExportToImage overloaded method to export a document. To specify export options, create a ImageExportOptions class instance and pass this instance to the invoked method, or use PrintingSystem‘s ExportOptions.Image property.
using System;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
XtraReport report = new XtraReport() {
Name = "HelloWorld",
Bands = {
new DetailBand(){
Controls={
new XRLabel(){
Text="Hello World!"
}
}
}
}
};
// Create a document from the report.
report.CreateDocument();
// imageExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
string imageExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".image";
// Specify export options and export the document.
// Uncomment the lines below to specify export options in an ImageExportOptions class instance.
// ImageExportOptions ImageExportOptions = new ImageExportOptions();
// ImageExportOptions.ExportMode = ImageExportMode.SingleFile;
// report.PrintingSystem.ExportToImage(imageExportFile, ImageExportOptions);
// Comment the lines below if you specified export options in an ImageExportOptions class instance above.
report.PrintingSystem.ExportOptions.Image.ExportMode = ImageExportMode.SingleFile;
report.PrintingSystem.ExportToImage(imageExportFile);
Export a Control
Call a PrintingLink.ExportToImage overloaded method to export a control. To specify export options, create a ImageExportOptions class instance and pass this instance to the invoked method.
using System;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
DevExpress.XtraCharts.ChartControl chart = new DevExpress.XtraCharts.ChartControl() {
Name = "IncomeByQuarter",
Series = {
new DevExpress.XtraCharts.Series("2019", DevExpress.XtraCharts.ViewType.Bar)
}
};
// Create a printing link.
PrintingSystem printingSystem = new PrintingSystem();
PrintableComponentLink link = new PrintableComponentLink();
printingSystem.Links.Add(link);
link.Component = chart;
// imageExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
string imageExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + chart.Name + ".image";
// Specify export options and export the control.
ImageExportOptions ImageExportOptions = new ImageExportOptions();
ImageExportOptions.ExportMode = ImageExportMode.SingleFile;
link.ExportToImage(imageExportFile, ImageExportOptions);
Settings and Limitations
The options that can be specified for a document exported to an image are stored in the ImageExportOptions class. Use the report’s ExportOptions.Image property to access these options.
To specify the text rendering quality, especially in low-DPI images and in images with transparent background, use the ImageExportOptions.TextRenderingMode property.
The following image formats are supported:
- BMP
- EMF (not supported on Linux)
- WMF (not supported on Linux)
- GIF
- JPEG
- PNG
- TIFF
- SVG
A report watermark appears in the exported image only in SingleFilePageByPage or DifferentFiles export modes.