Skip to main content

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.v23.2.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
Workbook workbook = new Workbook();

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

workbook.LoadDocument("Document.xlsx");
// Export the workbook to PDF.
workbook.ExportToPdf("ExportedDocument.pdf");