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:
- Add a reference to the DevExpress.Xpf.Spreadsheet.v24.2.dll assembly to your project.
Import the following namespaces into your code:
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");