pdfExport

Fired when the user clicks the "Export to PDF" toolbar button.

Event Data

e.sender kendo.ui.Grid

The widget instance which fired the event.

e.preventDefault Function

If invoked the grid will not save the generated file.

e.promise Promise

A promise that will be resolved when the export completes.

The promise progress handler will be called periodically with the following arguments:

  • page - The current page content. An instance of drawing.Group
  • pageNumber - The current page number
  • progress - Number if the range 0 to 1, indicating the progress of the current export operation
  • totalPages - The total number of pages

Any changes to the page content group will be applied, including PDF page options. This allows you to change paper size, orientation and apply transformations on each individual page.

Example - Monitor export progress

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  toolbar: ["pdf"],
  columns: [
    { field: "name" }
  ],
  dataSource: {
    data: [{ name: "Jane Doe"},
           { name: "John Doe"},
           { name: "Tim Doe"},
           { name: "Alice Doe"}],
    pageSize: 2
  },
  pageable: true,
  pdf: {
      allPages: true
  },
  pdfExport: function(e) {
    e.promise
    .progress(function(e) {
/* The result can be observed in the DevTools(F12) console of the browser. */
        console.log(kendo.format("{0:P} complete", e.progress));
    })
    .done(function() {
        alert("Export completed!");
    });
  }
});
var grid = $("#grid").data("kendoGrid");
grid.saveAsPDF();
</script>

Example - Change page orientation on the fly

<div id="grid"></div>
<script>
$("#grid").kendoGrid({
  toolbar: ["pdf"],
  columns: [
    { field: "name" }
  ],
  dataSource: {
    data: [{ name: "Jane Doe"},
           { name: "John Doe"},
           { name: "Tim Doe"},
           { name: "Alice Doe"}],
    pageSize: 2
  },
  pdf: {
    allPages: true,
    paperSize: "A3",
    landscape: false
  },
  pdfExport: function(e) {
    e.promise
    .progress(function(e) {
        if (e.pageNumber > 1) {
            e.page.options.pdf = {
                landscape: true
            };
        }
    });
  }
});
var grid = $("#grid").data("kendoGrid");
grid.saveAsPDF();
</script>
In this article