How to: Print the Document
- 2 minutes to read
This example demonstrates how to use a PrintableComponentLink to print a document loaded in a Workbook instance.
This example demonstrates how to invoke the Print Preview form for a Workbook instance (workbook, in this example). To do this, follow the steps below.
- Create a new PrintingSystem instance for creating and printing a document.
- Create a PrintableComponentLink printing link with the specified printing system and assign the workbook to the PrintableComponentLinkBase.Component property.
- Generate a document to print by calling the LinkBase.CreateDocument method.
- Call the PrintableComponentLink.Print method or the PrintableComponentLink.ShowPreviewDialog method to invoke the print preview form that enables the user to print a document or save it in PDF or as a graphic file.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/spreadsheet-document-server-api-e4339
using DevExpress.Spreadsheet;
using DevExpress.XtraPrinting;
// Invoke the Print Preview dialog for the workbook.
using (PrintingSystem printingSystem = new PrintingSystem()) {
using (PrintableComponentLink link = new PrintableComponentLink(printingSystem)) {
link.Component = workbook;
link.CreateDocument();
link.ShowPreviewDialog();
}
}
Note
Embeddeed charts are not printed by default.
To print a document that contains embedded charts, in addition to the above steps, add a reference to the DevExpress.XtraSpreadsheet.v17.2.dll assembly and register required services as shown in the code snippet below:
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraSpreadsheet.Services.Implementation;
//...
workbook.AddService(typeof(IChartControllerFactoryService), new ChartControllerFactoryService());
workbook.AddService(typeof(IChartImageService), new ChartImageService());
See Also