PDF Export

The Kendo UI Grid wrapper for Vue enables you to export its content to PDF.

To configure the PDF export functionality of the native Vue Grid by Kendo UI, refer to the native Vue Grid by Kendo UI documentation.

Basics

You can export Kendo UI Data Grid wrapper for Vue data to PDF and use the client PDF-export functionality which is server-agnostic and which relies on the Kendo UI Drawing library. To enable the export to PDF, include the corresponding command to the toolbar of the Grid and configure the settings accordingly. For example, you can choose to export all pages, margins, paper size, font, and so on. To initiate the PDF export programmatically, call the saveAsPdf method from the client API of the Grid.

<div id="vueapp" class="vue-app">
    <kendo-datasource ref="datasource1"
                      :type="'odata'"
                      :transport-read-url="'https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers'"
                      :page-size='20'>
    </kendo-datasource>

    <kendo-grid :height="600"
                :data-source-ref="'datasource1'"
                :sortable="true"
                :pageable-refresh="true"
                :pageable-page-sizes="true"
                :pageable-button-count="5"
                :toolbar="['pdf']"
                :pdf-all-pages="true"
                :pdf-avoid-links="true"
                :pdf-paper-size="'A4'"
                :pdf-margin="{ top: '2cm', left: '1cm', right: '1cm', bottom: '1cm' }"
                :pdf-landscape="true"
                :pdf-repeat-headers="true"
                :pdf-scale="0.8">
        <kendo-grid-column :field="'ContactName'"
                           :title="'Contact Name'"
                           :width="200"></kendo-grid-column>
        <kendo-grid-column :field="'ContactTitle'"
                           :title="'Contact Title'"></kendo-grid-column>
        <kendo-grid-column :field="'CompanyName'"
                           :title="'Company Name'"></kendo-grid-column>
        <kendo-grid-column :field="'Country'"
                           :width="150"></kendo-grid-column>
    </kendo-grid>
</div>
Vue.use(GridInstaller);
Vue.use(DataSourceInstaller);

new Vue({
    el: '#vueapp',
    data () {
        return {
            schemaModelFields: {
                UnitsInStock: { type: "number" },
                ProductName: { type: "string" },
                UnitPrice: { type: "number" },
                UnitsOnOrder: { type: "number" },
                UnitsInStock: { type: "number" }
            },
            groupDefinition: {
                field: "UnitsInStock",
                aggregates: [
                    { field: "ProductName", aggregate: "count" },
                    { field: "UnitPrice", aggregate: "sum"},
                    { field: "UnitsOnOrder", aggregate: "average" },
                    { field: "UnitsInStock", aggregate: "count" }
                ]
            },
            aggregateDefinition: [
                { field: "ProductName", aggregate: "count" },
                { field: "UnitPrice", aggregate: "sum" },
                { field: "UnitsOnOrder", aggregate: "average" },
                { field: "UnitsInStock", aggregate: "min" },
                { field: "UnitsInStock", aggregate: "max" }
            ]
        }
    }
})

Customization

To modify the content of the exported PDF file, use CSS rules. When the user clicks the Export button, the page creates an individual element. Then it applies the CSS rules to that element and the files and the styling settings are exported.

.k-pdf-export .k-grid {
    font-family: "DejaVu Sans", "Arial", sans-serif;
}

To enable compression in the PDF output, load the pako zip library (pako_deflate.min.js) from CDN. This approach improves the performance of the Grid and increases the size of the content that can be exported.

<script src="https://kendo.cdn.telerik.com/2018.2.620/js/pako_deflate.min.js"></script>

The Standard PDF fonts do not support Unicode characters. That is why, when you use one of the Kendo UI LESS-based themes which are referenced from CDN, provide the source files for embedding them in order for the output to use TrueType fonts.

kendo.pdf.defineFont({
    "DejaVu Sans": "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans.ttf",
    "DejaVu Sans|Bold": "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Bold.ttf",
    "DejaVu Sans|Bold|Italic": "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Oblique.ttf",
    "DejaVu Sans|Italic": "https://kendo.cdn.telerik.com/2016.2.607/styles/fonts/DejaVu/DejaVuSans-Oblique.ttf",
    "WebComponentsIcons": "https://kendo.cdn.telerik.com/2017.1.223/styles/fonts/glyphs/WebComponentsIcons.ttf"
});

For more information, refer to the runnable StackBlitz example which uses the Pako library from CDN, the Default LESS theme, and external fonts.

In this article