Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.v24.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");