This tutorial shows how to export a weekly event calendar created using DayPilot event calendar to a PDF file.
Features:
Sample code:
C#
private void ExportToPdf() { PdfDocument doc = new PdfDocument(); doc.Info.Title = "DayPilot Calendar PDF Export"; doc.Info.Author = "DayPilot"; PdfPage page = doc.AddPage(); page.Size = (PageSize) Enum.Parse(typeof (PageSize), ListPageSize.SelectedValue); page.Orientation = (PageOrientation)Enum.Parse(typeof(PageOrientation), ListPageOrientation.SelectedValue); MemoryStream mem = new MemoryStream(); doc.Save(mem, false); Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=calendar.pdf"); mem.WriteTo(Response.OutputStream); Response.End(); }
VB
Private Sub ExportToPdf() ' create a new PDF document Dim doc As New PdfDocument() doc.Info.Title = "DayPilot Calendar PDF Export" doc.Info.Author = "DayPilot" ' add a page Dim page_Renamed As PdfPage = doc.AddPage() ' set PDF page properties (size and orientation) page_Renamed.Size = CType(System.Enum.Parse(GetType(PageSize), ListPageSize.SelectedValue), PageSize) page_Renamed.Orientation = CType(System.Enum.Parse(GetType(PageOrientation), ListPageOrientation.SelectedValue), PageOrientation) ' save the PDF file to MemoryStream Dim mem As New MemoryStream() doc.Save(mem, False) ' send the output stream to the browser Response.Clear() Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "attachment;filename=calendar.pdf") mem.WriteTo(Response.OutputStream) Response.End() End Sub
The sample project with C# and VB source code is available for download.