|
| 1 | +--- |
| 2 | +title: PDF Export |
| 3 | +page_title: PDF Export |
| 4 | +description: "Export the Telerik UI Gantt for {{ site.framework }} to PDF." |
| 5 | +slug: htmlhelpers_gantt_pdf_export_aspnetcore |
| 6 | +position: 5 |
| 7 | +--- |
| 8 | + |
| 9 | +# PDF Export |
| 10 | + |
| 11 | +The Telerik {{ site.product_short }} Gantt component provides a built-in PDF export functionality. |
| 12 | + |
| 13 | +For a runnable example, refer to the [demo on exporting the Gantt to PDF](https://demos.telerik.com/{{ site.platform }}/gantt/pdf-export). |
| 14 | + |
| 15 | +## Getting Started |
| 16 | + |
| 17 | +To enable PDF export: |
| 18 | + |
| 19 | +1. Include the corresponding toolbar command and set the export settings. |
| 20 | + * [Toolbar configuration](https://docs.telerik.com/{{ site.platform }}/api/kendo.mvc.ui.fluent/ganttbuilder#toolbarsystemaction) |
| 21 | + * [PDF export configuration](https://docs.telerik.com/{{ site.platform }}/api/kendo.mvc.ui.fluent/ganttbuilder#pdfsystemaction) |
| 22 | +1. Include the `Pako Deflate` library in the page to enable compression. |
| 23 | + |
| 24 | +The following example demonstrates how to enable the PDF export functionality of the Gantt. |
| 25 | + |
| 26 | +{% if site.core %} |
| 27 | +```HtmlHelper |
| 28 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 29 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 30 | +
|
| 31 | + @(Html.Kendo().Gantt<TaskViewModel, DependencyViewModel>() |
| 32 | + .Name("gantt") |
| 33 | + .Toolbar(tb => |
| 34 | + { |
| 35 | + tb.Pdf(); |
| 36 | + }) |
| 37 | + .Pdf(pdf => pdf |
| 38 | + .FileName("Gantt Export.pdf") |
| 39 | + ) |
| 40 | + //...additional Gantt configuration... |
| 41 | + ) |
| 42 | +``` |
| 43 | +```TagHelper |
| 44 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 45 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 46 | + |
| 47 | + <kendo-gantt name="gantt"> |
| 48 | + <toolbars> |
| 49 | + <toolbar name="pdf"> |
| 50 | + </toolbar> |
| 51 | + </toolbars> |
| 52 | + <pdf file-name="Gantt Export.pdf"> |
| 53 | + </pdf> |
| 54 | + <!-- ...additional Gantt configuration... --> |
| 55 | + </kendo-gantt> |
| 56 | +``` |
| 57 | +{% else %} |
| 58 | +```HtmlHelper |
| 59 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 60 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 61 | +
|
| 62 | + @(Html.Kendo().Gantt<TaskViewModel, DependencyViewModel>() |
| 63 | + .Name("gantt") |
| 64 | + .Toolbar(tb => |
| 65 | + { |
| 66 | + tb.Add().Name("pdf"); |
| 67 | + }) |
| 68 | + .Pdf(pdf => pdf |
| 69 | + .FileName("Gantt Export.pdf") |
| 70 | + ) |
| 71 | + //...additional Gantt configuration... |
| 72 | + ) |
| 73 | +``` |
| 74 | +{% endif %} |
| 75 | + |
| 76 | +## Saving Files on the Server |
| 77 | + |
| 78 | +To send the generated file to a remote endpoint, use the `ProxyURL()` and `ForceProxy()` methods. |
| 79 | + |
| 80 | +{% if site.core %} |
| 81 | +```HtmlHelper |
| 82 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 83 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 84 | +
|
| 85 | + @(Html.Kendo().Gantt<TaskViewModel, DependencyViewModel>() |
| 86 | + .Name("gantt") |
| 87 | + .Toolbar(tb => |
| 88 | + { |
| 89 | + tb.Pdf(); |
| 90 | + }) |
| 91 | + .Pdf(pdf => pdf |
| 92 | + .FileName("Gantt Export.pdf") |
| 93 | + .ForceProxy(true) |
| 94 | + .ProxyURL(Url.Action("PdfExportSave", "Home")) |
| 95 | + ) |
| 96 | + //...additional Gantt configuration... |
| 97 | + ) |
| 98 | +``` |
| 99 | +```TagHelper |
| 100 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 101 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 102 | + |
| 103 | + <kendo-gantt name="gantt"> |
| 104 | + <toolbars> |
| 105 | + <toolbar name="pdf"> |
| 106 | + </toolbar> |
| 107 | + </toolbars> |
| 108 | + <pdf file-name="Gantt Export.pdf" |
| 109 | + force-proxy="true" |
| 110 | + proxy-url="@Url.Action("PdfExportSave", "Home")"> |
| 111 | + </pdf> |
| 112 | + </kendo-gantt> |
| 113 | +``` |
| 114 | +{% else %} |
| 115 | +```HtmlHelper |
| 116 | + <!-- Load Pako Deflate library to enable PDF compression --> |
| 117 | + <script src="https://unpkg.com/pako/dist/pako_deflate.min.js"></script> |
| 118 | +
|
| 119 | + @(Html.Kendo().Gantt<TaskViewModel, DependencyViewModel>() |
| 120 | + .Name("gantt") |
| 121 | + .Toolbar(tb => |
| 122 | + { |
| 123 | + tb.Add().Name("pdf"); |
| 124 | + }) |
| 125 | + .Pdf(pdf => pdf |
| 126 | + .FileName("Gantt Export.pdf") |
| 127 | + .ForceProxy(true) |
| 128 | + .ProxyURL(Url.Action("PdfExportSave", "Home")) |
| 129 | + ) |
| 130 | + //...additional Gantt configuration... |
| 131 | + ) |
| 132 | +``` |
| 133 | +{% endif %} |
| 134 | + |
| 135 | +```ServerProxy |
| 136 | + [HttpPost] |
| 137 | + public ActionResult PdfExportSave(string contentType, string base64, string fileName) |
| 138 | + { |
| 139 | + var fileContents = Convert.FromBase64String(base64); |
| 140 | + return File(fileContents, contentType, fileName); |
| 141 | + } |
| 142 | +``` |
| 143 | + |
| 144 | +## Embedding Unicode Characters |
| 145 | + |
| 146 | +The default fonts in PDF files do not provide Unicode support. To support international characters, you have to embed an external font. For more information on the supported [Deja Vu font family](https://dejavu-fonts.github.io) as part of the Kendo UI distributions and other fonts, refer to the Kendo UI for jQuery article on [custom fonts and PDF](https://docs.telerik.com/kendo-ui/framework/drawing/pdf-output/embedded-fonts). |
| 147 | + |
| 148 | +The following example demonstrates how to handle custom fonts. |
| 149 | + |
| 150 | +```Style |
| 151 | + <style> |
| 152 | + /* |
| 153 | + Use the DejaVu Sans font for display and embedding in the PDF file. |
| 154 | + The standard PDF fonts have no support for Unicode characters. |
| 155 | + */ |
| 156 | + .k-gantt { |
| 157 | + font-family: "DejaVu Sans", "Arial", sans-serif; |
| 158 | + } |
| 159 | +
|
| 160 | + /* Hide the Gantt toolbar during export */ |
| 161 | + .k-pdf-export .k-gantt-toolbar { |
| 162 | + display: none; |
| 163 | + } |
| 164 | + </style> |
| 165 | +``` |
| 166 | + |
| 167 | +## Further Reading |
| 168 | + |
| 169 | +* [PDF output by the Kendo UI Drawing library](https://docs.telerik.com/kendo-ui/framework/drawing/pdf-output/overview) |
| 170 | +* [Drawing DOM elements with the Kendo UI Drawing library](https://docs.telerik.com/kendo-ui/framework/drawing/dom-elements/overview) |
| 171 | +* [Saving files with Kendo UI](https://docs.telerik.com/kendo-ui/framework/saving-files) |
| 172 | + |
| 173 | +## See Also |
| 174 | + |
| 175 | +* [Server-Side API](/api/gantt) |
| 176 | +* [PDF Export of the Telerik UI Gantt for {{ site.framework }} Demo](https://demos.telerik.com/{{ site.platform }}/gantt/pdf-export) |
0 commit comments