How to: Export a Chart to PDF
This topic explains how to export chart content to a file and to a stream in the PDF format.
Use the DevExpress Printing Library to export the chart. Add references to the following assemblies:
- DevExpress.XtraPrinting.19.1
- DevExpress.Printing.v19.1.Core
Use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported.
Call the ChartControl.ExportToPdf method to export the chart.
using System.IO;
using DevExpress.XtraCharts;
// ...
private void OnButtonClick(object sender, EventArgs e) {
if(chartControl1.IsPrintingAvailable) {
// Exports the chart in the vector-based format to a PDF file.
chartControl1.OptionsPrint.ImageFormat = DevExpress.XtraCharts.Printing.PrintImageFormat.Metafile;
chartControl1.ExportToPdf("D://Output1.pdf", new DevExpress.XtraPrinting.PdfExportOptions { ConvertImagesToJpeg = false });
// Exports to a stream as PDF.
FileStream pdfStream = new FileStream("D://Output2.pdf", FileMode.Create);
chartControl1.ExportToPdf(pdfStream);
// ...
pdfStream.Close();
}
}