Skip to main content

CachedReportSource Class

A component that manages caching logic and acts as a mediator between a report and a Document Viewer.

Namespace: DevExpress.XtraPrinting.Caching

Assembly: DevExpress.Printing.v24.2.Core.dll

Declaration

[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.CachedReportSource.bmp")]
public class CachedReportSource :
    CachedReportSourceBase,
    IReport,
    IDocumentSource,
    ILink,
    IComponent,
    IDisposable,
    IServiceProvider,
    IExtensionsProvider

Remarks

Use the CachedReportSource component to avoid memory consumption-related issues when you display, print or export large documents. This component generates a report document and caches each generated page in the specified storage. The following document storages are available:

You can also inherit from the DocumentStorage class to implement a custom document storage.

The following code demonstrates how to create a CachedReportSource instance:

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

When you dispose of the CachedReportSource component, the storage it uses is disposed of as well. The storage content is cleared if DocumentStorage.ClearOnDispose is enabled.

Note

The disposal can take some time if it is invoked while the document is generated, because the CachedReportSourceBase.StopPageBuilding method waits until the currently generated page is ready.

Display Large Reports

To display a report in a Document Viewer, assign the CachedReportSource component to the DocumentViewer.DocumentSource (WinForms) / DocumentViewerControl.DocumentSource (WFP) property. Refer to the Quick Start (WinForms) / Quick Start (WPF) section for details.

The document created by the CachedReportSource component is regenerated each time users edit it in the Document Viewer (when they change margins, paper format, or watermark).

Merge Large Reports

When you merge a large document with another document, call the CachedReportSourceBase.CreateDocument method beforehand to generate the document. Then, use the XtraReport.ModifyDocument or CachedReportSourceBase.ModifyDocument method to manipulate the generated document’s page set.

To print or export a large document in code without displaying it in a Document View, use the CachedReportSource component’s CachedReportSourceBase.CreateDocument method to generate the document. Then access the CachedReportSource.PrintingSystem property to utilize the document’s Printing System and its print and export methods.

Use Caching in Web Reporting Applications

Use the CachedReportSource class in WinForms and WPF reporting applications. To utilize document caching in Web applications, use the CachedReportSourceWeb class. For more information on document caching, review the following help topic: Web Document Viewer Cache Management.

Example: Export Pages to Separate Files

Create the DocumentOperationService class descendant on the server. The PerformOperation method should use the CachedReportSource to process a new report instance. Merge it with an existing report and export to PDF using the CachedSource.PrintingSystem.ExportToPdf method:

 public class CustomDocumentOperationService : DocumentOperationService {
        public override DocumentOperationResponse PerformOperation(DocumentOperationRequest request, PrintingSystemBase initialPrintingSystem, PrintingSystemBase printingSystemWithEditingFields) {
            var outputReport = new XtraReport();
            var cachedSource = new CachedReportSource(outputReport, new MemoryDocumentStorage());
            int counter = 0;         
            foreach (Page documentP in printingSystemWithEditingFields.Pages) {
                cachedSource.CreateDocument();
                cachedSource.ModifyDocument(x => {
                    x.InsertPage(0, documentP);
                });
                cachedSource.PrintingSystem.ExportToPdf(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + "Document" + counter.ToString() + "Page" + ".pdf");
                counter++;
            }
            return new DocumentOperationResponse {Succeeded=true, Message = "Report was exported to separate files."};
}

On the client side, handle the CustomizeMenuActions event and add a custom toolbar item. In the toolbar item’s click action, call the PerformCustomDocumentOperation method to run the server-side DocumentOperationService class descendant methods.

Limitations

See Also