Print and Export

  • 4 minutes to read

You can print a chart and export it to multiple file formats.

ChartPrintingExporting_main

Make sure that your project references the DevExpress.XtraPrinting.20.1 and DevExpress.Printing.v20.1.Core assemblies to be capable of doing the following:

Immediately Print a Chart

When you need to immediately print a chart using the default printer, use the following code.


private void onButtonClick(object sender, EventArgs e) {
    if (chartControl.IsPrintingAvailable) {
        chartControl.Print();
    }
}

The table below lists API members in use.

Member Description
ChartControl.Print Prints the chart.
ChartControl.IsPrintingAvailable Indicates whether or not the chart is available for printing.

Print/Export a Chart Using the Print Preview

The chart can be printed/exported from the Print Preview. To display the Print Preview with a toolbox or with a Ribbon, use one of the following methods.

Method Description
ChartControl.ShowPrintPreview Invokes the chart Print Preview with a toolbox.
ChartControl.ShowRibbonPrintPreview Invokes the chart Print Preview with a Ribbon.

The following code demonstrates how to invoke the chart Print Preview with a Ribbon.


private void onButtonClick(object sender, RoutedEventArgs e) {
      chartControl.ShowRibbonPrintPreview(this);
}

To immediately print a chart using the Print Preview, select the Quick Print item.

To show the standard print dialog before printing a chart, select the Print item in the Print Preview.

To export a chart using the Print Preview dialog, select the desired file format in the Export item's drop-down list.

Export a Chart from Code

You can export a chart to numerous formats using the methods below.

Method Description
ChartControl.ExportToHtml Exports a chart to an HMTL file.
ChartControl.ExportToImage Exports a chart to an image.
ChartControl.ExportToMht Exports a chart to an MHT file.
ChartControl.ExportToPdf Exports a chart to a PDF file.
ChartControl.ExportToXls Exports a chart to an XLS file.
ChartControl.ExportToXlsx Exports a chart to an XLSX file.
ChartControl.ExportToRtf Exports a chart to an RTF file.
ChartControl.ExportToDocx Exports a chart to a DOCX file.
ChartControl.ExportToSvg Exports a chart to an SVG image.

The following code shows how to export a chart to the specified PDF file.


private void onButtonClick(object sender, EventArgs e) {
    // Exports the chart in the vector-based format to a PDF file.
    chartControl.OptionsPrint.ImageFormat = DevExpress.XtraCharts.Printing.PrintImageFormat.Metafile;
    chartControl.ExportToPdf("D://document.pdf", new DevExpress.XtraPrinting.PdfExportOptions { ConvertImagesToJpeg = false });
}

Configure the Print/Export Options

You can configure chart options before printing/exporting a chart. For this, examine the following code example.


private void onButtonClick(object sender, EventArgs e) {
    chartControl.OptionsPrint.SizeMode = PrintSizeMode.Stretch;
    chartControl.OptionsPrint.ImageFormat = PrintImageFormat.Bitmap;
    if (chartControl.IsPrintingAvailable) {
        chartControl.Print();
    }
}

The example above uses the following properties.

Property Description
ChartControl.OptionsPrint Provides access to the chart print options.
ChartOptionsPrint.SizeMode Specifies a chart size mode. To set this property, use the PrintSizeMode enumeration items.
ChartOptionsPrint.ImageFormat Specifes a format of an image to represent a chart in the Print Preview. To set this property, use the PrintImageFormat enumeration items.
See Also