v7.3.0

PdfExport
Feature

Generates PDF/PNG files from the Grid component.

A server-side service is required to perform the export operation. Check out PDF Export Server documentation and installation steps here

When your server is up and running, it listens to requests. The Export feature sends a request to the specified URL with the HTML fragments. The server generates a PDF (or PNG) file and returns a download link (or binary, depending on sendAsBinary config). Then the Export feature opens the link in a new tab and the file is automatically downloaded by your browser. This is configurable, see openAfterExport config.

The exportServer URL must be configured. The URL can be localhost if you start the server locally, or your remote server address.

This feature will not work properly when Store uses lazyLoad

Usage

const grid = new Grid({
    features : {
        pdfExport : {
            exportServer : 'http://localhost:8080' // Required
        }
    }
})

// Opens popup allowing to customize export settings grid.features.pdfExport.showExportDialog();

// Simple export grid.features.pdfExport.export({ columns : grid.columns.map(c => c.id) }).then(result => { // Response instance and response content in JSON let { response } = result; });

Exporting large datasets

PDF Export feature supports streaming generated pages using WebSocket connection. If server does not support it, then feature will use single HTTP request with all the data. For big datasets that can lead to page crashing when running out of memory. WebSocket support allows feature to send pages to the server one by one and then wait for the server to respond with a link to the file or the file itself.

Feature will check API status of the export server and starting from version 2.0.1, the server response will allow WebSocket connections.

Exporters

There are three exporters available by default: singlepage, multipage and multipagevertical:

  • singlepage - generates single page with content scaled to fit the provided paperFormat
  • multipage - generates as many pages as required to fit all requested content, unscaled
  • multipagevertical - a combination of two above: it scales content horizontally to fit into page width and then puts overflowing content on vertical pages. Like a scroll.

Loading resources

If you face a problem with loading resources when exporting, the cause might be that the application and the export server are hosted on different servers. This is due to Cross-Origin Resource Sharing (CORS). There are 2 options how to handle this:

  • Allow cross-origin requests from the server where your export is hosted to the server where your application is hosted;
  • Copy all resources keeping the folder hierarchy from the server where your application is hosted to the server where your export is hosted and setup paths using translateURLsToAbsolute config and configure the export server to give access to the path:
const grid = new Grid({
    features : {
        pdfExport : {
            exportServer : 'http://localhost:8080',
            // '/resources' is hardcoded in WebServer implementation
            translateURLsToAbsolute : 'http://localhost:8080/resources'
        }
    }
})
// Following path would be served by this address: http://localhost:8080/resources/
node ./src/server.js -h 8080 -r web/application/styles

where web/application/styles is a physical root location of the copied resources, for example:

This feature is disabled by default. For info on enabling it, see GridFeatures.

See also

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Set to true to align row top to the page top on every exported page. Only applied to multipage export.

  • Export server will navigate to this url first and then will change page content to whatever client sent. This option is useful with react dev server, which uses a strict CORS policy.

  • A config object to apply to the ExportDialog widget.

    Has a corresponding runtime exportDialog property.

  • exportMask : String"Generating pages..."

    A message to be shown when Export feature is performing export.

  • exportProgressMask : String"Waiting for response from server..."

    A message to be shown when export is almost done.

  • URL of the print server.

  • Config for exporter.

  • exporterType : 'singlepage'/'singlepageunscaled'/'multipage'/'multipagevertical'/Stringsinglepage

    Type of the exporter to use. Should be one of the configured exporters

  • exporters : Exporter[]["SinglePageExporter","SinglePageUnscaledExporter","MultiPageExporter","MultiPageVerticalExporter"]

    List of exporter classes to use in export feature

  • An object containing the Fetch options to pass to the export server request. Use this to control if credentials are sent and other options, read more at MDN.

  • When true links are converted to absolute by combining current window location (with replaced origin) with resource link. When false links are converted by combining new origin with resource link (for angular)

  • Defines if printed/exported page should contain @page style with paper size and orientation specified.

  • When true, page will attempt to download generated file.

  • False to open in the current tab, true - in a new tab

  • Set to true to show column headers on every page. This will also set alignRows to true. Only applies to MultiPageVertical exporter.

  • Set to true to receive binary file from the server instead of download link.

  • Set to false to not show Toast message on export error.

  • useBrowserPrint : Booleanfalse
    private

    When true, export feature will use an iframe and browser's default print dialog, which allows saving as PDF. Content is optimized for chrome/edge to exact page size in the specified orientation and no margins. If you only see grid header or blank pages, try using different scale value in the print dialog NOTE: Not supported in Safari. Print works, but Safari cannot seem to fit content to one page correctly.

  • This config forces exporter to always use rendered column width. Used by Agenda view in Calendar

  • Determines whether to stream exported pages directly to the export server using WebSocket connection to offload client application. false - use legacy mode which first collected all pages locally and then passed them in a single request true - stream pages directly to the server null (default) - ask export server for WebSocket support and use it if possible

    Has a corresponding runtime webSocketAvailable property.

  • Maximum time in ms to wait for the response over the websocket connection

    Has a corresponding runtime webSocketRequestTimeout property.

  • fileFormat : 'pdf'/'png'pdf

    Format of the exported file, either pdf or png.

  • Name of the exported file.

  • orientation : 'portrait'/'landscape'portrait

    Orientation. Options are portrait and landscape.

  • paperFormat : 'A0'/'A1'/'A2'/'A3'/'A4'+ 3 moreA4

    Export paper format. Available options are A1...A5, Legal, Letter.

  • rowsRange : 'all'/'visible'all

    Specifies which rows to export. all for complete set of rows, visible for only rows currently visible.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • When export is started from GUI (ExportDialog), export promise can be accessed via this property.

  • Returns the instantiated export dialog widget as configured by exportDialog

    Has a corresponding exportDialog config.

  • isExporting : Boolean
    READONLY

    This yields true if an export/print operation is ongoing.

  • Determines whether to stream exported pages directly to the export server using WebSocket connection to offload client application. false - use legacy mode which first collected all pages locally and then passed them in a single request true - stream pages directly to the server null (default) - ask export server for WebSocket support and use it if possible

    Has a corresponding webSocketAvailable config.

  • Maximum time in ms to wait for the response over the websocket connection

    Has a corresponding webSocketRequestTimeout config.

  • isPdfExport : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of PdfExport class, or subclass thereof.

Functions

Functions are methods available for calling on the class

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class
    id: pdfExport

    Source path

    Grid/feature/export/PdfExport.js

    Demo

    examples/export

    Contents