Skip to main content

Export Large Reports

  • 2 minutes to read

Use the CachedReportSource component to preview a large report that contains over 10,000 pages. The CachedReportSource component stores generated pages in the file system, database, or compressed memory streams. The dedicated storage allows you to overcome memory allocation limitations and avoid the OutOfMemory exception. The size of a document is limited only by the available storage space. A substantial increase in the number of pages does not lead to a significant increase in memory consumption.

The CachedReportSource may decrease overall performance because of the time required to store a page and retrieve it from the storage. You should test your application and decide whether it can benefit from the CachedReportSource component.

The following code creates a CachedReportSource instance that uses the MemoryDocumentStorage storage type for the specified report.

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

Instead of memory storage, you can use the FileDocumentStorage, or DbDocumentStorage storage types.

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");
}