Skip to main content
A newer version of this page is available.

ChartControl.ExportToPdf(String) Method

Exports the chart’s layout to the specified PDF file.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v19.1.UI.dll

Declaration

public void ExportToPdf(
    string filePath
)

Parameters

Name Type Description
filePath String

A String specifying the full path (including the file name and extension) where the PDF file will be created.

Remarks

If a file under the specified file path exists, the new file replaces it.

To show the standard Print dialog, use the ChartControl.Print method. The dialog allows end-users to print the chart, select the printer (if required), specify the range of pages to print, the number of copies, etc.

To display the DevExpress Print Preview use one of the following methods.

Method Description
ChartControl.ShowPrintPreview Creates the print document and displays the Print Preview of the document.
ChartControl.ShowRibbonPrintPreview Creates the print document and displays the Print Preview with the Ribbon toolbar of the document.

To export the chart, use the appropriate ExportTo~ method (e.g., ChartControl.ExportToHtml, ChartControl.ExportToPdf, etc.)

Important

Note that, exporting to raster and vector images is implemented by the Chart and does not require any library.

The chart can be previewed, printed and exported to other formats only if the Printing library is available. Make sure you add a reference to the DevExpress.XtraPrinting.v19.1 assembly.

Also note that chart export to PDF requires the DevExpress.Pdf.Core library to be available.

Example

This topic explains how to export chart content to a file and to a stream in the PDF format.

  1. Use the DevExpress Printing Library to export the chart. Add references to the following assemblies:

    • DevExpress.XtraPrinting.19.1
    • DevExpress.Printing.v19.1.Core
  2. Use the ChartControl.IsPrintingAvailable property to check whether the chart can be exported.

  3. 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();
    }
}
See Also