PDF Export
The TreeList provides built-in PDF export for hierarchical data. Add the PDF command to the toolbar to let users download TreeList data as a PDF document.
For a runnable example, refer to the TreeList PDF export demo.
Enable PDF Export
To enable PDF export:
- Add the
pdfcommand to the TreeListtoolbarconfiguration. - Configure the
pdfoptions. - For large PDF documents, include the Pako library to enable compression.
The following example adds an Export to PDF button to the TreeList toolbar and configures the exported document.
<script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script>
<div id="treelist"></div>
<script>
$("#treelist").kendoTreeList({
toolbar: ["pdf"],
columns: [
{ field: "Name", title: "Name" },
{ field: "Position", title: "Position" }
],
dataSource: [
{ id: 1, parentId: null, Name: "Jane Doe", Position: "Chief Executive Officer" },
{ id: 2, parentId: 1, Name: "John Doe", Position: "Chief Technology Officer" }
],
pdf: {
fileName: "Employees.pdf",
paperSize: "A4",
landscape: true
}
});
</script>
Export All Pages and Configure Layout
By default, the TreeList exports the current page. Set pdf.allPages to true to export all pages, and use PDF options such as paperSize, landscape, and margin to configure the document layout.
pdf: {
allPages: true,
paperSize: "A4",
landscape: true,
margin: { top: "1cm", right: "1cm", bottom: "1cm", left: "1cm" }
}
Export Programmatically
You can call the saveAsPDF method when a user interacts with an external element to export the TreeList data to a PDF file.
$("#export").on("click", function() {
var treeList = $("#treelist").data("kendoTreeList");
treeList.saveAsPDF();
});
The pdfExport event fires before the TreeList saves the generated PDF. Use its e.promise argument to determine when the export completes.