Printing Links
- 3 minutes to read
This topic explains what the printing links are and how they are used to create documents that are ready to be previewed, printed and exported.
This topic consists of the following sections.
Links Overview
DXPrinting creates documents by linking data with templates (DataTemplate).
Depending on data provider, templates are either provided by a link or by an associated control (e.g., when printing DevExpress grids).
Using Links to Print Data
To create a document and publish it (print, export, or show it in a Document Preview window), perform the following steps.
- Create a link according to the type of data (SimpleLink, CollectionViewLink or PrintableControlLink);
- Call the required method of the PrintHelper class with the link instance passed to this method as a parameter.
All link types derive from the LinkBase class. From it, derives the TemplatedLink class that defines templates for the following document sections (that are similar to report bands in XtraReports).
- report header (TemplatedLink.ReportHeaderData and TemplatedLink.ReportHeaderTemplate);
- page header (TemplatedLink.PageHeaderData and TemplatedLink.PageHeaderTemplate);
- page footer (TemplatedLink.PageFooterData and TemplatedLink.PageFooterTemplate);
- report footer (TemplatedLink.ReportFooterData and TemplatedLink.ReportFooterTemplate);
Link Types
The following link types are available in DXPrinting.
SimpleLink is used to create documents based on plain linear data. Its essential members are:
- the SimpleLink.DetailTemplate property, which specifies a template for each data row (detail data);
- the SimpleLink.DetailCount property, which specifies the number of detail records (the number of times the CreateDetail event is raised to create a document detail area);
- the SimpleLink.CreateDetail event, which is raised for each detail record created and which also allows for the providing of data for the document detail area.
For a code example, see How to: Use the Simple Link.
CollectionViewLink provides extra options to print objects, which implement the ICollectionView interface.
Apart from the CollectionViewLink.DetailTemplate property, this link type provides the CollectionViewLink.GroupInfos property. This option allows you to specify distinct templates for GroupInfo.HeaderTemplate and GroupInfo.FooterTemplate properties, so that you can set off each grouping level within a document in a different style.
Among grouping options, there are the GroupInfo.PageBreakAfter and GroupInfo.PageBreakBefore properties to start each group from a new page.
In addition, the GroupInfo.RepeatHeaderEveryPage property defines whether a group header is repeated on each page.
For a code example, see How to: Use the CollectionView Link.
PrintableControlLink is specially intended to print DXGrid and Pivot Grid by DevExpress.
When printing a grid, a link can be created based on the grid’s TableView.
This special link type supports the creation of multi-column documents (where data is arranged on a page in several columns), by using its TemplatedLink.ColumnLayout and TemplatedLink.ColumnWidth properties.
- LegacyPrintableComponentLink is intended to print DevExpress controls for Windows Forms that implement the IPrintable interface.
CompositeLink allows you to combine content of several printing links in a single document. This link’s constructor accepts the collection of printing links (TemplatedLink descendants) to compose.
Refer to How to: Use the Composite Link for a code sample.
In addition to the above link types, you can create custom links inherited from the LinkBase class.