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).
After creating a printing link, it should be assigned to an appropriate view model (the DocumentPreviewModelBase class descendant), which is then assigned to a Document Viewer, from where it can be printed and exported.
#Using Links to Print Data
To create a document and show it in a Document Preview, perform the following steps.
- Create a link according to the type of data (SimpleLink, CollectionViewLink or PrintableControlLink);
- Assign the link to a corresponding view model (LinkPreviewModel or );
- Assign the model to the DocumentViewer.Model property;
- Call the LinkBase.CreateDocument method.
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.PageFooterData);
#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 or not 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 GridControl 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 the TemplatedLink.ColumnLayout and TemplatedLink.ColumnWidth properties.
For a code example, see How to: Update the Document Preview According to the Changes Made in GridControl.
Note that apart from using pre-defined link types, you can create custom types inherited from the LinkBase class.