New to Telerik UI for ASP.NET MVC? Download free 30-day trial

PDF Export

The Telerik UI for ASP.NET MVC Scheduler component provides a built-in PDF export functionality.

For a runnable example, refer to the demo on exporting the Scheduler to PDF.

Getting Started

To enable PDF export:

  1. Include the corresponding toolbar command and set the export settings.
  2. Include the Pako Deflate library in the page to enable compression.

The following example demonstrates how to enable the PDF export functionality of the Scheduler.

    <!-- Load Pako Deflate library to enable PDF compression -->
    <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script>

    @(Html.Kendo().Scheduler<SchedulerModel>()
        .Name("scheduler")
        .Toolbar(t => t.Pdf())
        .Pdf(pdf => pdf
            .FileName("Kendo UI Scheduler Export.pdf")
        )
        .DataSource(d => d
            .Model(m =>
            {
                m.Id(f => f.Id);
                m.Field(f => f.Title).DefaultValue("No title");
            })
            .Read(read => read.Action("PDF_Export_Read", "Scheduler"))
        )
    )

Changing the Export Settings

By default, the paper size of the exported document is determined by the size of the Scheduler on the viewport. You have the ability to further alter the paper size and dimensions of the document as per your requirements.

The following example demonstrates how to additionally configure the Scheduler's PaperSize(), Margin(), and Landscape() PDF export settings.

    @(Html.Kendo().Scheduler<SchedulerModel>()
        .Name("scheduler")
        .Toolbar(t => t.Pdf())
        .Pdf(pdf => pdf
            .Landscape(true)
            .Margin(20, 50, 20, 50)
            .PaperSize("auto")
            .FileName("Kendo UI Scheduler Export.pdf")
        )
        .DataSource(d => d
            .Model(m =>
            {
                m.Id(f => f.Id);
                m.Field(f => f.Title).DefaultValue("No title");
            })
            .Read(read => read.Action("PDF_Export_Read", "Scheduler"))
        )
    )

Saving Files on the Server

To send the generated file to a remote endpoint, use the ProxyURL() and ForceProxy() methods.

     @(Html.Kendo().Scheduler<SchedulerModel>()
        .Name("scheduler")
        .Toolbar(t => t.Pdf())
        .Pdf(pdf => pdf
            .FileName("Kendo UI Scheduler Export.pdf")
            .ForceProxy(true)
            .ProxyURL(Url.Action("Pdf_Export_Save", "Scheduler"))
        )
        .DataSource(d => d
            .Model(m =>
            {
                m.Id(f => f.Id);
                m.Field(f => f.Title).DefaultValue("No title");
            })
            .Read(read => read.Action("PDF_Export_Read", "Scheduler"))
        )
    )
    [HttpPost]
    public ActionResult Pdf_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);
        return File(fileContents, contentType, fileName);
    }

Embedding Unicode Characters

The default fonts in PDF files do not provide Unicode support. To support international characters, you have to embed an external font. For more information on the supported Deja Vu font family as part of the Kendo UI distributions and other fonts, refer to the Kendo UI for jQuery article on custom fonts and PDF.

The following example demonstrates how to handle custom fonts.

  @(Html.Kendo().Scheduler<SchedulerModel>()
      .Name("scheduler")
      .Toolbar(t => t.Pdf())
      .Pdf(pdf => pdf
          .FileName("Kendo UI Scheduler Export.pdf")
      )
      .DataSource(d => d
          .Model(m =>
          {
              m.Id(f => f.Id);
              m.Field(f => f.Title).DefaultValue("No title");
          })
          .Read(read => read.Action("PDF_Export_Read", "Scheduler"))
      )
  )
   <style>
        /*
            Use the DejaVu Sans font for display and embedding in the PDF file.
            The standard PDF fonts have no support for Unicode characters.
        */
        .k-scheduler {
            font-family: "DejaVu Sans", "Arial", sans-serif;
        }

        /* Hide toolbar, navigation and footer during export */
        .k-pdf-export .k-scheduler-toolbar,
        .k-pdf-export .k-scheduler-navigation .k-nav-today,
        .k-pdf-export .k-scheduler-navigation .k-nav-prev,
        .k-pdf-export .k-scheduler-navigation .k-nav-next,
        .k-pdf-export .k-scheduler-footer {
            display: none;
        }
   </style>

Further Reading

See Also

In this article