# Angular TreeList PDF Export

The [Angular TreeList](https://www.telerik.com/kendo-angular-ui-develop/components/treelist) provides robust options for exporting its content to PDF, enabling you to create professional, print-ready documents directly from your application.

To enable the PDF export functionality in the TreeList:

1. Import the `KENDO_TREELIST_PDF_EXPORT` utility array in your standalone component (or `PDFModule`).
2. Include the [`<kendo-treelist-pdf>`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent) component within the TreeList to configure and control the export behavior.
3. Trigger the export by using one of the following methods:
   * The [`kendoTreeListPDFCommand`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcommanddirective) directive, which binds export functionality to a button or another UI element.
   * The [`saveAsPDF`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/export/pdf-export#triggering-export-externally) method, which programmatically triggers the export.

```html
<kendo-treelist [data]="staff" [kendoTreeListFlatBinding]="staff" idField="id" parentIdField="parentId">
    <ng-template kendoTreeListToolbarTemplate>
        <button kendoTreeListPDFCommand [svgIcon]="filePdfIcon">Export to PDF</button>
    </ng-template>
    <kendo-treelist-column [expandable]="true" field="name" title="Name"></kendo-treelist-column>
    ...
    <kendo-treelist-pdf fileName="MedicalStaff.pdf" paperSize="A4"></kendo-treelist-pdf>
</kendo-treelist>
```

The following example demonstrates how to set up the PDF export functionality of the TreeList.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/basic/source.txt)

## Exporting All Pages

By default, the TreeList exports only the current page of data. To export all pages, set the [`allPages`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#allpages) option to `true`. When you enable the option, the [`pageChange`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#pagechange) event fires with `skip` set to 0 and `take` to the total number of records. The original `skip` and `take` are restored after the export completes.

> * The export of all TreeList pages requires all records (although off-screen) to be rendered at once.
> * The exact maximum number of exportable rows varies depending on the browser, system resources, template complexity, and other factors.
> * Verify your own worst-case scenarios in each browser you intend to support.
> * When the TreeList templates contain asynchronously rendered content such as Kendo UI for Angular Charts, use the [`delay`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#delay) option to specify the number of milliseconds by which the export will be postponed. This ensures that all content is rendered before the export starts.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/all-pages/source.txt)

## Fitting Content to Paper Size

By default, the paper size of the exported document is determined by the size of the TreeList on the screen. However, you can define a specific paper size using the [`paperSize`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#papersize) property. Supported values include standard sizes like `"A4"`, `"Letter"`, or custom dimensions (e.g., `["300mm", "500mm"]`).

When a specific `paperSize` is set, the content automatically fits to the specified dimensions. Sometimes, this may result in cutting out content in the PDF output. You can further control the scaling by using the [`scale`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#scale) property to override the automatic scale factor. For example, you can adjust the scale to make room for additional page elements like headers or footers.

The following example demonstrates how to set the `paperSize` to `"A4"` and adjust the `scale` to `0.6`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/paper-size/source.txt)

## Customizing Exported Columns

The Angular TreeList allows you to control which columns are included in the exported PDF document. This feature is particularly useful when you want to exclude certain columns from the export or rearrange the order of the exported columns.

To specify the columns for export:

1. Define the columns you want to include in the exported PDF by adding [`<kendo-treelist-column>`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/columncomponent) components inside the [`<kendo-treelist-pdf>`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent) component.
2. (Optional) If your TreeList uses column groups, include [`<kendo-treelist-column-group>`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/columngroupcomponent) components to organize the exported columns.

The following example demonstrates how to export only a subset of columns in the PDF output, even though the TreeList displays more columns by default.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/export-columns/source.txt)

## Specifying Page Template

The TreeList enables you to specify a page template that helps you position the content and add headers, footers, and other elements. To style the exported document, use the built-in [`kendoTreeListPDFTemplate`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdftemplatedirective) and apply the necessary CSS styles. During the PDF export, the template is positioned in a container with the specified paper size.

> When using the template, you are required to set the [paperSize](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#papersize) option.

The following example demonstrates how you can add headers and footers to the exported PDF file using the built-in `kendoTreeListPDFTemplate`.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/page-template/source.txt)

## Exporting Multiple TreeLists to the Same PDF

By default, each TreeList is exported to a separate document.

To export multiple TreeLists to the same document:

1. Use the [`drawPDF`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#drawpdf) method to get the group of TreeLists for export.
2. Set the [`exportPDF`](https://www.telerik.com/kendo-angular-ui-develop/components/drawing/api/pdf/exportpdf) method to export the group.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/multiple-treelists/source.txt)

## Triggering Export Externally

The TreeList enables you to trigger the export operation by calling the [`saveAsPDF`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#saveaspdf) method.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/save-as-pdf/source.txt)

## Exporting Groups of Rows to Separate Pages

You can manually split the exported data into separate pages by using the [forcePageBreak](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#forcepagebreak) option of the `PDFComponent`.

1. Sort the data by the respective field.
2. By utilizing the [`rowClass`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent#rowclass) function, add the class that will be used by the `forcePageBreak` option to the first row of each items group.

The following example demonstrates how to render items at the same hierarchy level (hospital, division, unit, or staff) to a separate PDF page.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/export-groups-of-items-to-separate-pdf-pages/source.txt)

## Saving PDF Files

Internet Explorer 9 and Safari do not support the option for saving the exported PDF file and require the implementation of a [server proxy](https://www.telerik.com/kendo-angular-ui-develop/components/file-saver). To specify the server proxy URL, set the [`proxyURL`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#proxyurl) option.

Your project might require you to send the generated PDF file to a remote service. To achieve this behavior, set the `proxyUrl` and [`forceProxy`](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#forceproxy) to `true`. If the proxy returns `204 No Content`, the **Save As...** dialog will not appear on the client.

## Embedding Custom Fonts

The default fonts in the PDF files do not provide Unicode support. To render international characters, you need to embed an external font. For more information, refer to the article on [custom fonts and PDF export](https://www.telerik.com/kendo-angular-ui-develop/components/drawing/pdf-output).

In the following example, the `DejaVu Sans` font is loaded and applied to the exported PDF document.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/treelist/pdf-export/embedded-fonts/source.txt)

## Known Limitations

* The rendition of right-to-left content is not supported.

* Overflowing text is clipped and `text-overflow: ellipsis` is not supported.

* Images that are hosted on different domains might not be rendered unless the server provides the permissive [Cross-Origin HTTP headers](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image). Similarly, it might not be possible for fonts to load across domains.

  Even if the proper CORS headers are provided, Internet Explorer 9 will not be able to load images or fonts from another domain, which might raise an uncatchable security exception. To support Internet Explorer 9, host the images and fonts on the same domain as the application.

* The 1.5 PDF specification limits the maximum PDF document size to 5,080 x 5,080 millimeters (which equals to 200x200 inches). Larger files might not open in all viewers.

* Older browsers, such as Internet Explorer 9 and Safari, require you to implement a server proxy. For more information, refer to the [`proxyUrl` configuration section](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent#proxyurl).

## See Also

* [Exporting the TreeList to Excel](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/export/excel-export)
* [PDFComponent](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdfcomponent)
* [PDFTemplateDirective](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/pdftemplatedirective)
* [API Reference of the TreeListComponent](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api/treelistcomponent)
* [API Index of the TreeList](https://www.telerik.com/kendo-angular-ui-develop/components/treelist/api)
