Export Large Reports
- 2 minutes to read
Use the CachedReportSource component to export large reports. This component stores pages in a file system or database while a report document is generated, which improves memory consumption.
Create a CachedReportSource instance, specify a report to export 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. You can use the FileDocumentStorage, DbDocumentStorage or implement a custom storage instead.
To export a report, call the CreateDocument() or CreateDocumentAsync() method and invoke the export methods that the CachedReportSource object’s PrintingSystem exposes.
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button_Click(object sender, EventArgs e) {
var storage = new MemoryDocumentStorage();
var report = new XtraReport1();
var cachedReportSource = new CachedReportSource(report, storage);
cachedReportSource.CreateDocument();
cachedReportSource.PrintingSystem.ExportToDocx();
}
To export a large report to PDF format, consider using the PdfStreamingExporter class instead of calling the PrintingSystem‘s ExportToPdf methods to reduce the memory consumption.
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
// ...
private void button_Click(object sender, EventArgs e) {
var storage = new MemoryDocumentStorage();
var report = new XtraReport1();
var cachedReportSource = new CachedReportSource(report, storage);
cachedReportSource.CreateDocument();
new PdfStreamingExporter(report, true).Export("LargeReport.pdf");
Process.Start("LargeReport.pdf");
}