Printing
- 4 minutes to read
The PivotGridControl provides a fast and flexible way of bringing its contents to a printed page.
This topic demonstrates how to customize the printed version of the Pivot Grid Control, and lists the ways in which the pivot grid control can be printed. The document comprises the following subsections:
- Printing Basics
- Modifying Print Appearances
- Printing Options
- Example: How to Print a PivotGrid and Show its Print Preview
Note
Custom painting, alpha blending and color gradient features are not supported in the pivot grid control’s printout.
Printing Basics
Although the Pivot Grid control provides direct methods for printing displayed data, these methods delegate the printing functionality to the DevExpress Printing Library. If this library cannot be found, the printing and exporting functionality is not available. To ensure that Pivot Grid control printing/exporting is permitted, check the PivotGridControl.IsPrintingAvailable property’s value.
To print data from the Pivot Grid control, use the following methods.
Member | Description |
---|---|
PivotGridControl.Print | Prints the PivotGridControl. |
PivotGridControl.ShowPrintPreview | Opens the Print Preview window with a toolbar-based interface. |
PivotGridControl.ShowRibbonPrintPreview | Opens the Print Preview window with a Ribbon-based interface. |
These methods print and show a print preview of the data displayed by the Pivot Grid control.
The following example shows how to preview pivot grid data.
private void ShowPivotGridPreview(DevExpress.XtraPivotGrid.PivotGridControl pivotGrid) {
// Check whether or not the Pivot Grid control can be printed.
if(!pivotGrid.IsPrintingAvailable) {
MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error");
return;
}
// Opens the Preview window.
pivotGrid.ShowPrintPreview();
}
The image below illustrates the Preview window for a sample pivot grid.
Refer to the XtraPrinting Library documentation for more information on the functionality provided by the print preview window.
Modifying Print Appearances
By default, a printed pivot grid utilizes the same appearances as when it is displayed on screen. These appearance settings can be customized using the PivotGridControl.Appearance property. However, a Pivot Grid provides print appearances used to paint the pivot grid’s visual elements (field headers, data cells, etc.) in print output. To use print appearances instead of display appearances when the pivot grid is printed, set the PivotGridOptionsPrint.UsePrintAppearance option to true.
Use the pivot grid’s PivotGridControl.AppearancePrint property to set print appearances. This property provides access to the appearance settings for various Pivot Grid elements (for example, fields, data cells, etc.).
The appearance settings can be customized in the Print Appearances page of the PivotGrid Designer as well. You can save these settings to or restore these settings from an XML file.
Printing Options
The Pivot Grid provides a set of options that specify the Pivot Grid’s elements to be printed, as well as the appearance settings to be used to paint these elements when the pivot grid control is printed. These options can be accessed as follows.
At design time using the Print Settings page of the PivotGrid Designer.
In code, using the PivotGridControl.OptionsPrint property.
By an end-user at runtime in the Print Options dialog invoked by clicking the “Options” menu command in the Preview window.
Example: How to Print a PivotGrid and Show its Print Preview
The following example demonstrates how to print a Pivot Grid Control or show its Print Preview. To do this, you should use either the PivotGridControl.Print or PivotGridControl.ShowPrintPreview methods.
Note
The Pivot Grid Control can be printed and previewed only if the DevExpress.XtraPrinting Library is available. To verify that printing the Pivot Grid Control is possible, use the PivotGridControl.IsPrintingAvailable property.
When printing a PivotGridControl, the current print settings will be used to represent a PivotGridControl. Note that you can access and change these settings using the PivotGridControl.OptionsPrint property.
using DevExpress.XtraPivotGrid;
// ...
private void ShowPivotGridPreview(Pivot Grid Control pivotGrid) {
// Check whether the Pivot Grid Control can be previewed.
if (!pivotGrid.IsPrintingAvailable) {
MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
return;
}
// Open the Preview window.
pivotGrid.ShowPrintPreview();
}
private void PrintPivotGrid(Pivot Grid Control pivotGrid) {
// Check whether the Pivot Grid Control can be printed.
if (!pivotGrid.IsPrintingAvailable) {
MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
return;
}
// Print.
pivotGrid.Print();
}