Getting Started with the KendoReact PDF Generator

This guide provides essential information about using the KendoReact PDF Generator package. You will learn how to install the PDF Generator package, add a PDF Generator component to your project, style the component, and activate your license.

ninja-iconThe PDF Processing is part of KendoReact, a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.Start Free Trial

After completing this guide, you will be able to reproduce the following example.

Change Theme
Theme
Loading ...

Setting Up Your React Project

Before you install the KendoReact PDF Generator, make sure that you have a running React project. The easiest way to set up a React project is to use the Create React App approach that is described in the Get Started with KendoReact article.

Installing the Component

All KendoReact packages are distributed through npm and offer a similar installation experience. To use the PDF Generator component, start with the installation of the PDF Generator npm package and its dependencies. Use Node.js v5.0.0 or later.

sh
npm install --save @progress/kendo-react-pdf @progress/kendo-drawing @progress/kendo-licensing

Importing the Component

After installing the package, import the PDF Generator component in the React App.

In the src/App.js file of your React project, import the PDFExport and savePDF components from the PDF package. The PDFExport and savePDF provide the export and save functionality.

jsx
 // ES2015 module syntax
 import { PDFExport, savePDF } from '@progress/kendo-react-pdf';
jsx
// CommonJS format
const { PDFExport, savePDF } = require('@progress/kendo-react-pdf');

Using the Component

  1. Create a ref to the component that will later be used for the export

    jsx
    const pdfExportComponent = React.useRef(null);
  2. Create two functions that will handle the export, the first one will export with a method, and the second one will handle the component export.

    jsx
    const exportPDFWithMethod = () => {
        let element = document.querySelector('.k-grid') || document.body;
        savePDF(element, {
            paperSize: 'A4'
        });
    };
    const exportPDFWithComponent = () => {
        if (pdfExportComponent.current) {
            pdfExportComponent.current.save();
        }
    };
  3. Wrap the PDFExport component around the component that you wish to export.

    jsx
    <PDFExport ref={pdfExportComponent} paperSize="A4">
        <Grid
            style={{
                maxHeight: '400px'
            }}
            data={products}
        >
            <Column field="ProductID" title="ID" width="40px" />
            <Column field="ProductName" title="Name" width="250px" />
            <Column field="Category.CategoryName" title="CategoryName" />
            <Column field="UnitPrice" title="Price" width="80px" />
            <Column field="UnitsInStock" title="In stock" width="80px" />
        </Grid>
    </PDFExport>
  4. To style the PDF Export, install and import the Default theme, which is one of the three beautiful themes for KendoReact.

    4.1. Install the Default theme package.

    sh
    npm install --save @progress/kendo-theme-default

    4.2. Import the CSS file from the package in src/App.js. Add this import before your existing App.css import.

    jsx
    import '@progress/kendo-theme-default/dist/all.css';
  5. Build and run the application by typing the following command in the root folder of your project:

    sh
    npm start
  6. Navigate to http://localhost:3000 to see the KendoReact PDF Generator component on the page.

Activating Your License Key

Using any of the UI components in the KendoReact library requires either a commercial license key or an active trial license key.

Follow the instructions on the KendoReact My License page to activate your trial or commercial license. You can skip this step if your application already contains a KendoReact license file.

Dependencies

The PDF Generator package requires you to install the following peer dependencies in your application:

Package NameDescription
react 16.8.2*Contains the functionality necessary to define React components.
react-domContains the React renderer for the web.
@progress/kendo-licensingContains the internal infrastructure related to licensing.
@progress/kendo-drawingContains the KendoReact Drawing components.

Learning Resources