Back to Devexpress

How to: Export a Scheduler in PDF format

windowsforms-2265-controls-and-libraries-scheduler-examples-printing-and-reporting-how-to-export-a-scheduler-in-pdf-format.md

latest3.7 KB
Original Source

How to: Export a Scheduler in PDF format

  • Nov 13, 2018
  • 2 minutes to read

The following example demonstrates how to programmatically export a SchedulerControl in PDF format using the PrintableComponentLink object. A reference to DevExpress.XtraPrinting.v25.2.dll assembly is required.

Print options are specified via the SchedulerControl.ActivePrintStyle property.

csharp
using DevExpress.XtraPrinting;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Printing;
private void btnExport_Click(object sender, EventArgs e)
{
    SetPrintStyle();
    string filePath = "Test.pdf";
    PrintableComponentLink pcl = new PrintableComponentLink(new PrintingSystem());
    pcl.Component = this.schedulerControl1;
    pcl.CreateDocument();
    pcl.ExportToPdf(filePath);
    // Use the code below to open the file in an associated application.
    if (File.Exists(filePath)) {
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.FileName = filePath;
        process.Start();
    }
}

private void SetPrintStyle()
{
    DailyPrintStyle pStyle = this.schedulerControl1.ActivePrintStyle as DailyPrintStyle;

    // Set fonts for appointments and column headings.
    pStyle.AppointmentFont = new Font("Arial", 8, FontStyle.Regular);
    pStyle.HeadingsFont = new Font("Arial", 10, FontStyle.Regular);

    // Specify whether the Calendar header should be printed.
    pStyle.CalendarHeaderVisible = false;

    // Specify the intervals to print.
    DateTime dt = DateTime.Now;
    pStyle.PrintTime = new TimeOfDayInterval(dt.TimeOfDay, dt.AddHours(4).TimeOfDay);
    pStyle.StartRangeDate = dt.Date;
    pStyle.EndRangeDate = dt.AddDays(3).Date;

    // Specify resources to print.
    //pStyle.ResourceOptions.CustomResourcesCollection.Add(schedulerStorage1.Resources[0]);
    //pStyle.ResourceOptions.PrintCustomCollection = true;
    pStyle.PrintAllAppointments = false;
}
vb
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Printing
Private Sub btnExport_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnExport.Click
    SetPrintStyle()
    Dim filePath As String = "Test.pdf"
    Dim pcl As New PrintableComponentLink(New PrintingSystem())
    pcl.Component = Me.schedulerControl1
    pcl.CreateDocument()
    pcl.ExportToPdf(filePath)
    ' Use the code below to open the file in an associated application.
    If File.Exists(filePath) Then
        Dim process As New System.Diagnostics.Process()
        process.StartInfo.FileName = filePath
        process.Start()
    End If
End Sub

Private Sub SetPrintStyle()
    Dim pStyle As DailyPrintStyle = TryCast(Me.schedulerControl1.ActivePrintStyle, DailyPrintStyle)

    ' Set fonts for appointments and column headings.
    pStyle.AppointmentFont = New Font("Arial", 8, FontStyle.Regular)
    pStyle.HeadingsFont = New Font("Arial", 10, FontStyle.Regular)

    ' Specify whether the Calendar header should be printed.
    pStyle.CalendarHeaderVisible = False

    ' Specify the intervals to print.
    Dim dt As DateTime = DateTime.Now
    pStyle.PrintTime = New TimeOfDayInterval(dt.TimeOfDay, dt.AddHours(4).TimeOfDay)
    pStyle.StartRangeDate = dt.Date
    pStyle.EndRangeDate = dt.AddDays(3).Date

    ' Specify resources to print.
    'pStyle.ResourceOptions.CustomResourcesCollection.Add(schedulerStorage1.Resources[0]);
    'pStyle.ResourceOptions.PrintCustomCollection = true;
    pStyle.PrintAllAppointments = False
End Sub