PDF Export
The TreeList provides options for exporting its content to PDF.
To enable the PDF export, import the PDFModule and add the kendo-treelist-pdf
component to the Kendo UI TreeList for Angular. To initiate the PDF export, use the kendoTreeListPDFCommand
directive or the saveAsPDF
method.
Configuration
With regard to its PDF export, the TreeList enables you to:
- Export all its pages to PDF
- Fit its content within the paper size
- Customize the exported columns
- Specify a page template
- Export multiple TreeLists to a single PDF file
- Trigger the export externally
- Export groups of rows to separate pages
- Save the generated PDF files
- Embed custom fonts
Exporting All Pages
By default, the TreeList exports only the current page of data. To export all pages, set the allPages
option to true
. When you enable the option, the 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.
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 that will apply to the whole document. As a result, the content is scaled to fit the specified paper size. It is possible to override the automatic scale factor—for example, to make room for additional page elements.
To use the whole space that is available, the TreeList:
- Adjusts the column widths to fill the page.
- Adapts the number of rows for each page and places page breaks where appropriate.
- Omits the toolbar and pager.
Customizing Exported Columns
The TreeList enables you to specify the columns that will be exported. To configure them, include the <kendo-treelist-column>
and <kendo-treelist-column-group>
components inside the <kendo-treelist-pdf>
component.
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
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 option.
The following example demonstrates how you can add headers and footers to the exported PDF file using the built-in kendoTreeListPDFTemplate
.
Exporting Multiple TreeLists to the Same PDF
By default, the each TreeList is exported to a separate document.
To export multiple TreeLists to the same document:
- Use the
drawPDF
method to get the group of TreeLists for export. - Set the
exportPDF
method to export the group.
Triggering Export Externally
The TreeList enables you to trigger the export operation by calling the saveAsPDF
method.
Exporting Groups of Rows to Separate Pages
You can manually split the exported data into separate pages by using the forcePageBreak option of the PDFComponent
.
- Sort the data by the respective field.
- By utilizing the
rowClass
function, add the class that will be used by theforceBreakPage
option to the first row of each items group.
The following example demonstrates how to render items with the same Type to a separate PDF page.
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. To specify the server proxy URL, set the 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
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.
In the following example, the DejaVu Sans
font is loaded and applied to the exported PDF document.
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. 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.