| 
 | 1 | +---  | 
 | 2 | +title: Exporting TreeView to PDF in Kendo UI for jQuery  | 
 | 3 | +description: Learn how to export the Kendo UI for jQuery TreeView component data to a PDF file.  | 
 | 4 | +type: how-to  | 
 | 5 | +page_title: How to Export Kendo UI for jQuery TreeView Data to PDF  | 
 | 6 | +slug: export-treeview-to-pdf-kendo-ui-jquery  | 
 | 7 | +tags: kendo, treeview, export, pdf, drawing, drawdom  | 
 | 8 | +res_type: kb  | 
 | 9 | +ticketid: 1679577  | 
 | 10 | +---  | 
 | 11 | + | 
 | 12 | +## Environment  | 
 | 13 | + | 
 | 14 | +<table>  | 
 | 15 | +<tbody>  | 
 | 16 | +<tr>  | 
 | 17 | +<td>Product</td>  | 
 | 18 | +<td>Progress® Kendo UI® for jQuery TreeView</td>  | 
 | 19 | +</tr>  | 
 | 20 | +</tbody>  | 
 | 21 | +</table>  | 
 | 22 | + | 
 | 23 | +## Description  | 
 | 24 | +I want to export the data displayed in the Kendo UI for jQuery TreeView to a PDF file. However, I can't find a method or sample code in the TreeView documentation for exporting data to PDF. How can I achieve this functionality?  | 
 | 25 | + | 
 | 26 | +This knowledge base article also answers the following questions:  | 
 | 27 | +- How to generate a PDF from Kendo UI for jQuery TreeView component?  | 
 | 28 | +- What method can be used to export TreeView data to PDF in Kendo UI for jQuery?  | 
 | 29 | +- Can the Kendo UI Drawing library be used to export TreeView content to PDF?  | 
 | 30 | + | 
 | 31 | +## Solution  | 
 | 32 | +The Kendo UI for jQuery TreeView component does not have a built-in feature for exporting data to PDF directly. However, you can achieve this functionality by using the Kendo Drawing library. Follow the steps below to export the TreeView data to a PDF file:  | 
 | 33 | + | 
 | 34 | +1. Ensure that all nodes of the TreeView you wish to export are expanded. This is necessary because the export process requires all elements to be visible in the DOM.  | 
 | 35 | + | 
 | 36 | +2. Utilize the `kendo.drawing.drawDOM` method to convert the TreeView's DOM element into a drawing scene. Refer to the [Kendo Drawing documentation](https://docs.telerik.com/kendo-ui/api/javascript/drawing/methods/drawdom) for more details on this method.  | 
 | 37 | + | 
 | 38 | +3. Use the [`kendo.saveAs`](/api/javascript/kendo/methods/saveas) function to save the generated drawing scene as a PDF file.  | 
 | 39 | + | 
 | 40 | +Below is a sample runnable example demonstrating how to export the TreeView to PDF:  | 
 | 41 | + | 
 | 42 | +```dojo  | 
 | 43 | +  <div class="content-wrapper">  | 
 | 44 | +      <button id="btnPDF">Export PDF</button>       | 
 | 45 | +      <div id="treeview"></div>  | 
 | 46 | +    </div>  | 
 | 47 | +
  | 
 | 48 | +    <script>  | 
 | 49 | +      $(document).ready(function () {  | 
 | 50 | +        var rows = [];  | 
 | 51 | +        var isPDFExport = false;  | 
 | 52 | +
  | 
 | 53 | +        function onPDFExport(e) {           | 
 | 54 | +          var tree = $("#treeview").data("kendoTreeView");  | 
 | 55 | +          isPDFExport = true;  | 
 | 56 | +          tree.trigger("dataBound");  | 
 | 57 | +
  | 
 | 58 | +          //Handle Exporting to PDF  | 
 | 59 | +          setTimeout(function () {  | 
 | 60 | +            // Convert the DOM element to a drawing using kendo.drawing.drawDOM  | 
 | 61 | +            kendo.drawing  | 
 | 62 | +              .drawDOM($(".content-wrapper"))  | 
 | 63 | +              .then(function (group) {  | 
 | 64 | +                // Render the result as a PDF file  | 
 | 65 | +                return kendo.drawing.exportPDF(group, {  | 
 | 66 | +                  paperSize: "auto",  | 
 | 67 | +                  margin: {  | 
 | 68 | +                    left: "1cm",  | 
 | 69 | +                    top: "1cm",  | 
 | 70 | +                    right: "1cm",  | 
 | 71 | +                    bottom: "1cm",  | 
 | 72 | +                  },  | 
 | 73 | +                });  | 
 | 74 | +              })  | 
 | 75 | +              .done(function (data) {  | 
 | 76 | +                // Save the PDF file  | 
 | 77 | +                kendo.saveAs({  | 
 | 78 | +                  dataURI: data,  | 
 | 79 | +                  fileName: "TreeView.pdf",  | 
 | 80 | +                  // proxyURL: "Save",  | 
 | 81 | +                  //forceProxy: true, //use Server Proxy for files over 1MB  | 
 | 82 | +                });  | 
 | 83 | +              });  | 
 | 84 | +
  | 
 | 85 | +            $("#treeview").data("kendoTreeView").collapse(".k-treeview-item");  | 
 | 86 | +
  | 
 | 87 | +          }, 1000);  | 
 | 88 | +        }  | 
 | 89 | +
  | 
 | 90 | +        $("#btnPDF").kendoButton({  | 
 | 91 | +          click: onPDFExport,  | 
 | 92 | +          themeColor: 'success'  | 
 | 93 | +        });  | 
 | 94 | +
  | 
 | 95 | +        var serviceRoot = "https://demos.telerik.com/kendo-ui/service";  | 
 | 96 | +        homogeneous = new kendo.data.HierarchicalDataSource({  | 
 | 97 | +          transport: {  | 
 | 98 | +            read: {  | 
 | 99 | +              url: serviceRoot + "/Employees",  | 
 | 100 | +              dataType: "jsonp",  | 
 | 101 | +            },  | 
 | 102 | +          },  | 
 | 103 | +          schema: {  | 
 | 104 | +            model: {  | 
 | 105 | +              id: "EmployeeId",  | 
 | 106 | +              hasChildren: "HasEmployees",  | 
 | 107 | +            },  | 
 | 108 | +          },  | 
 | 109 | +        });  | 
 | 110 | +
  | 
 | 111 | +        $("#treeview").kendoTreeView({  | 
 | 112 | +          dataSource: homogeneous,  | 
 | 113 | +          dataTextField: "FullName",  | 
 | 114 | +          dataBound: function (e) {  | 
 | 115 | +            if (isPDFExport) {  | 
 | 116 | +              e.sender.expand(".k-treeview-item");  | 
 | 117 | +            }  | 
 | 118 | +          },  | 
 | 119 | +        });  | 
 | 120 | +      });  | 
 | 121 | +    </script>  | 
 | 122 | +```  | 
 | 123 | + | 
 | 124 | + | 
 | 125 | +## See Also  | 
 | 126 | + | 
 | 127 | +- [Kendo UI for jQuery TreeView Overview](https://docs.telerik.com/kendo-ui/controls/treeview/overview)  | 
 | 128 | +- [Kendo UI Drawing Overview](https://docs.telerik.com/kendo-ui/framework/drawing/overview)  | 
 | 129 | +- [Kendo UI Drawing API](https://docs.telerik.com/kendo-ui/api/javascript/drawing)  | 
 | 130 | +- [Kendo UI TreeView API](https://docs.telerik.com/kendo-ui/api/javascript/ui/treeview)  | 
0 commit comments