[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Collapse]Common Concepts
  [Collapse]Printing and Exporting
    Printing Overview
    Printing Custom Reports
  [Expand]Saving and Restoring Layouts
   Typed Styles
  [Expand]Touch Support
  [Expand]Formatting Values
   Prism Adapters
  [Expand]Data Sources
  [Expand]Performance Improvement
   XAML Namespaces
 [Expand]MVVM Framework
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Printing Custom Reports

The DXPrinting Library provides an easy approach to creating custom printed reports. This approach is based on special printing procedures called printing links. The DXPrinting Library introduces several types of printing links, each designed for rendering specific data objects, creating reports, and exporting and printing reports. You can create a custom printing link by inheriting your class from the LinkBase abstract class.

The following table lists the built-in types of printing links.

Printing Link Description
SimpleLink Renders data objects that contain linear data.
CollectionViewLink Renders data objects that contain hierarchical data and implement the System.ComponentModel.ICollectionView interface.
PrintableControlLink Renders DevExpress controls.

Expanded Creating Simple Links

Simple printing links are usually used to present non-hierarchical data in a report. Use these kind of links at such a time when data items do not need to be divided into groups.

Once created, simple links must be supplied with data. To do this, specify the number of data items via the SimpleLink.DetailCount property and handle the SimpleLink.CreateDetail event. The event is raised each time a new data item is required and as many times as specified by the SimpleLink.DetailCount property. In the handler, assign the new data item to the CreateAreaEventArgs.Data event parameter's property. The index of the required data item can be obtained using the CreateAreaEventArgs.DetailIndex property.

Along with data items, visual presentation must be specified. To do this, create a System.Windows.DataTemplate, which should be applied to each data item, and then assign it to the link's SimpleLink.DetailTemplate property.

Expanded Creating Collection View Links

Collection view printing links are useful when you need to display data from a hierarchical data source in your report or simply when data items should be shown split into several groups.

To assign data to a collection view link, create an object that implements the System.ComponentModel.ICollectionView interface. This can be a System.Windows.Data.CollectionViewSource object. After supplying this object with data, assign it to the link's CollectionViewLink.CollectionView property.

When data is specified, you should define its visual presentation. To do this, create a System.Windows.DataTemplate that should be applied to each data item and assign it to the link's CollectionViewLink.DetailTemplate property. To provide the link with the information about item grouping, create a GroupInfo object for each grouping level, and specify a template that should be applied to each group header in the current grouping level via the GroupInfo.HeaderTemplate property. Then, add the GroupInfo objects to the link's CollectionViewLink.GroupInfos collection.

Expanded Creating Printable Control Links

Printable control links are used to render controls and data objects that implement the IPrintableControl or IRootDataNode interface. For instance, the TableView object can be rendered by a printable control link.

To create a printable control link, simply pass the appropriate control or data object to the PrintableControlLink (see PrintableControlLink.PrintableControlLink) constructor.

Expanded Page Settings

The DXPrinting Library provides a number of settings that allow you to customize the page options of the report.

You can include page headers and footers into your report, as well as the header and footer of the whole document. To do this, specify their templates via the TemplatedLink.PageHeaderTemplate, TemplatedLink.PageFooterTemplate, TemplatedLink.ReportHeaderTemplate and TemplatedLink.ReportFooterTemplate properties, respectively. These templates can also be provided with some custom data by assigning the appropriate data objects to the TemplatedLink.PageHeaderData, TemplatedLink.PageFooterData, TemplatedLink.ReportHeaderData and TemplatedLink.ReportFooterData properties, respectively.

The following table lists other properties used to specify report page settings.

Property Description
LinkBase.CustomPaperSize Gets or sets a size of custom paper (measured in hundredths of an inch).
LinkBase.DocumentName Gets or sets the name of the document.
LinkBase.Landscape Gets or sets a value indicating whether the page orientation is landscape.
LinkBase.Margins Gets or sets the margins of a report page (measured in hundredths of an inch).
LinkBase.MinMargins Specifies the minimum printer margin values.
LinkBase.PaperKind Gets or sets the type of paper for the document.
LinkBase.SuppressAutoRebuildOnPageSettingsChange Gets or sets a value indicating whether it is necessary to suppress rebuilding the document every time a link's page settings are changed.

Expanded Exporting and Printing Reports

After the link object is created and supplied with data, you can create a document from the link by calling the LinkBase.CreateDocument method. Now the report is generated, and you can print and export it, as well as display it in the DocumentPreview control. To do this, it is necessary to create a new LinkPreviewModel instance with the current link as an initialization parameter, and assign it to the DocumentPreview.Model property.

Use the LinkBase.ShowPrintPreview method to open the report preview window. To open a modal preview window, use the LinkBase.ShowPrintPreviewDialog method. The printing dialog can be invoked via the LinkBase.Print method. To print the report without opening any dialogs, use the LinkBase.PrintDirect method.

The following table lists methods used to export a report into different formats.

Method Description
LinkBase.ExportToCsv Exports a report to the specified file path in CSV format using the specified CSV-specific options.
LinkBase.ExportToHtml Exports a report to the specified file path in HTML format using the specified HTML-specific options.
LinkBase.ExportToImage Exports a report to the specified file path in image format using the specified image-specific options.
LinkBase.ExportToMht Exports a report to the specified stream in MHT format using the specified MHT-specific options.
LinkBase.ExportToPdf Exports a report to the specified stream in PDF format using the specified PDF-specific options.
LinkBase.ExportToRtf Exports a report to the specified file path in RTF format using the specified RTF-specific options.
LinkBase.ExportToText Exports a report to the specified file path in text format using the specified TXT-specific options.
LinkBase.ExportToXls Exports a report to the specified file path in XLS format using the specified XLS-specific options.
LinkBase.ExportToXlsx Exports a report to the specified stream in XLSX format using the specified XLSX-specific options.
LinkBase.ExportToXps Exports a report to the specified stream in XPS format using the specified XPS-specific options.

Is this topic helpful?​​​​​​​