Printing
- 3 minutes to read
The WPF Scheduler Suite uses DevExpress Reporting to create a printable scheduler report with the SchedulerControl’s data, preview it and print or export it to PDF.
Overview
To print the SchedulerControl, create a scheduler report template, bind it to the scheduler print adapter, and show the resulting document in a Document Preview window. The Document Preview window UI commands enable users to print the document and save it as a PDF or image file.
Add the following NuGet package to the project to be able to print the Scheduler:
A scheduler report template is an XtraSchedulerReport class object, which is a XtraReport class descendant, offering many useful features available in XtraReports.
XtraScheduler Reports are created similarly to XtraReports. See the Getting Started with DevExpress Reporting document for more information on reports.
Refer to the How to: Print a Scheduler Using Reports from a Document Preview Window document for instructions on how to create a scheduler report.
Scheduler Reporting Specifics
The report retrieves scheduler data from the print adapter (SchedulerPrintAdapter object) the SchedulerPrintAdapter.AssignToReport method assigns to it.
The scheduler report requires a print adapter to interact with a scheduler control. A print adapter is the SchedulerPrintAdapter object instance accessible using the SchedulerControl.SchedulerPrintAdapter property. To bind a report to a print adapter, call the SchedulerPrintAdapter.AssignToReport method.
The print adapter composes a data set used in the report and allows you to filter the Scheduler data by providing a set of validation events which can change appointment and resource collections before they are passed to a report, or adjust a report’s time interval and work time. For example, you can handle the SchedulerPrintAdapter.ValidateAppointments event to print appointments which meet specific criteria.
The base XtraReport class is a report bands container with report controls placed inside them. Scheduler Reporting adds a set of special controls described in the Scheduler Report Controls and Components document.
Preview, Print, Export
To preview a report, open it in the Document Preview window. The DocumentPreviewControl enables the end-user to print a report or export it to PDF.
This code snippet contains the PrintScheduler method which performs the following tasks:
- Instantiate the XtraSchedulerReport descendant. The class can be designed in Visual Studio or loaded from a template.
- Specify the time interval of the report’s scheduler data.
- Connect the SchedulerPrintAdapter to the report instance.
- Call the PrintHelper.ShowPrintPreview method to create a document and display it using the built-in document preview window.
using DevExpress.Mvvm;
using DevExpress.Xpf.Printing;
using DevExpress.Xpf.Printing.Native;
using DevExpress.Xpf.Scheduling;
using DevExpress.XtraPrinting.Native;
using System.Windows;
namespace PrintingExample {
public static class MyPrintHelper {
public static Window mainWindow { get; set; }
public static void PrintScheduler(SchedulerControl scheduler) {
XtraSchedulerReport1 report = new XtraSchedulerReport1();
DateTimeRange dateTimeRange = scheduler.VisibleIntervals[0];
scheduler.SchedulerPrintAdapter.DateTimeRange = dateTimeRange;
scheduler.SchedulerPrintAdapter.AssignToReport(report);
PrintHelper.ShowPrintPreview(mainWindow, report);
}
}
}
Customization
You can change report elements’ appearance and content by handling the TimeCellsControlBase.AppointmentViewInfoCustomizing, TimeCellsControlBase.InitAppointmentDisplayText and TimeCellsControlBase.InitAppointmentImages events and the XtraSchedulerReport controls’ CustomDraw* event series.
Scripting
Advanced users can benefit from scripting - they can write code for specific event handlers in the End-User Report Designer. See the Scripting article for more information.