A newer version of this page is available. Switch to the current version.

How to: Use the WPF Chart Rendering Mechanism When Printing or Exporting a Workbook to PDF

Charts are converted to images using the WinForms rendering mechanism when you print a workbook containing embedded charts or export it to PDF. However, if you use Spreadsheet Document API in a WPF application, you can use WPF charts when printing or exporting a document to PDF.

Follow the steps below to perform this task:

  1. Add a reference to the DevExpress.Xpf.Spreadsheet.v19.1.dll assembly to your project.
  2. Import the following namespaces into your code:

    using DevExpress.Xpf.Spreadsheet.Services;
    using DevExpress.XtraSpreadsheet.Services;
    using DevExpress.XtraSpreadsheet.Services.Implementation;
  3. Register the following services using the Workbook.ReplaceService<T> method to substitute the default chart rendering mechanism with the WPF one:

    • DevExpress.Xpf.Spreadsheet.Services.ChartControllerFactoryService
    • DevExpress.XtraSpreadsheet.Services.Implementation.WpfChartImageService

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T603465.

Workbook workbook = new Workbook();

// Replace the default chart rendering mechanism with the WPF one. 
workbook.ReplaceService<IChartControllerFactoryService>(new ChartControllerFactoryService());
workbook.ReplaceService<IChartImageService>(new WpfChartImageService());

// Export the workbook to PDF.