Back to Devexpress

Export Large Reports

xtrareports-400038-feature-guide-to-devexpress-reports-store-and-distribute-reports-export-reports-export-large-reports.md

latest4.7 KB
Original Source

Export Large Reports

  • Feb 18, 2026
  • 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.

csharp
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting.Caching;
//...
    var storage = new MemoryDocumentStorage();
    var report = new XtraReport1();
    var cachedReportSource = new CachedReportSource(report, storage);
vb
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting.Caching
'...
    Private storage = New MemoryDocumentStorage()
    Private report = New XtraReport1()
    Private 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.

csharp
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();
}
vb
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting.Caching
' ...

Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim storage = New MemoryDocumentStorage()
    Dim report = New XtraReport1()
    Dim cachedReportSource = New CachedReportSource(report, storage)
    cachedReportSource.CreateDocument()
    cachedReportSource.PrintingSystem.ExportToDocx()
End Sub

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.

csharp
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");
}
vb
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting.Caching
' ...

Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim storage = New MemoryDocumentStorage()
    Dim report = New XtraReport1()
    Dim cachedReportSource = New CachedReportSource(report, storage)
    cachedReportSource.CreateDocument()
    CType(New PdfStreamingExporter(report, True), PdfStreamingExporter).Export("LargeReport.pdf")
        Process.Start("LargeReport.pdf")
End Sub