PivotGrid Printing

This blog post discusses the explicit support for printing in the PivotGridControl for the WPF platform through a helper and the Syncfusion PrintPreviewControl. Using the helper, you can print the PivotGridControl as it is, with options to insert a header, footer, and title for the print preview window. The PrintPreviewControl itself exposes a toolbar with options to launch print dialog, navigate between pages, zoom, and handle page settings.

Printing

Printing enables us to maintain a static copy of the current UI view for future reference, and is a basic functionality that every UI component should support. To be considered useful, a printed document should accurately display the look and feel of the UI component.

Syncfusion Print APIs

 

  • IPrintDocument – An interface defined to support creating print documents with some basic methods and properties for the UI component.
  • IGridPaginator – An interface defined to support creating print views from the grid view in the form of pages.
  • PrintPreviewControl – A control through which the UI component can be viewed in preview mode, zoomed, and printed.

 

Print Helper

PrintGridDocument, a helper class utilizing the IPrintDocument and IGridPaginator interfaces, frames the print visual of pivot grid views in the form of pages. It can be bound to the PrintPreviewControl, which can then be added as window content for user view. The following code sample illustrates how to enable printing in the PivotGrid control:

;

PivotGridControl pivotGrid1 = obj as PivotGridControl; // obj refers to PivotGridControl object
Window printWindow = new Window();
pivotGrid1.InternalGrid.PrintRange = GridRangeInfo.Table();
PrintGridDocument printDocument = new PrintGridDocument(pivotGrid1);
printDocument.Margin = new Thickness(20);
PrintPreviewControl navigationControl = new PrintPreviewControl(printDocument);
navigationControl.HeaderTemplate = HeaderTemplate;
navigationControl.FooterTemplate = FooterTemplate;
printWindow.Title = "Print Preview";
printWindow.Content = navigationControl;
printWindow.ShowDialog();

 

Sample

This sample showcases the previously mentioned feature in an MVVM pattern. Its UI lets you to print the header, footer, and grouping bar optionally as shown in the following image:

Figure 1: The PrintPreview control with a view of the PivotGrid control

bi