Skip to main content

Create a Custom Print Preview

  • 2 minutes to read

If you want to preview a report and then print or export it, you can invoke the built-in Print Preview dialog, as described in the following help topic: Invoke the Built-in Print Preview Form. A Reporting subscription is required to use the built-in dialog in your application.

An alternative method is to place the DocumentViewer control on the form and bind it to a report. A WinForms subscription is required in order to complete this custom print preview.

If your WinForms application targets .NET 6+, add the DevExpress.Win.Design NuGet package to this application to use the DocumentViewer control.

This topic shows how to create a custom Print Preview form with the DocumentViewer control. Follow the steps outlined below:

  1. Switch to the application’s main form in Visual Studio and press CTRL+ALT+X to open the Toolbox. Expand the DX.23.2: Reporting category and drop the DocumentViewer control onto the form.

    winforms-add-document-viewer-control

  2. Click the Document Viewer’s smart tag and select the report in the Document Source drop-down menu to assign a report to the DocumentViewer.DocumentSource property.

    winforms-document-viewer-document-source

    Note

    Rebuild the project so that the newly added reports appear in the Document Source drop-down menu.

    NET Core projects do not display reports in this list. You should assign the DocumentSource property in code:

      documentViewer1.DocumentSource = new XtraReport1();
    
  3. Optional. If you want to preview a large report that might consume a lot of memory, bind the DocumentViewer control to the CachedReportSource component instead. This component stores document pages in a file system or database when the document is generated and thus allows you to avoid issues related to memory consumption.

    Check the Cache Document Source option in the Document Viewer’s smart tag after you set the Document Source property:

    winforms-document-viewer-cached-document-source

    This adds the CachedReportSource component to the form.

    winforms-document-viewer-cachedreportsource-storage

    You can assign one of the following ready-to-use document storages to the CachedReportSource.Storage property:

  4. Click the Document Viewer’s smart tag and select the Create Ribbon Toolbar action to create the Ribbon toolbar:

    winforms-document-viewer-create-toolbar

  5. Run the application. A form with the DocumentViewer control that displays a sample report is shown in the following image:

    winforms-document-viewer-form-result

See Also