PdfExport
Feature
Generates PDF/PNG files from the Grid component.
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.
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 paperFormatmultipage- generates as many pages as required to fit all requested content, unscaledmultipagevertical- 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
- Print - Print the grid
- ExcelExporter - Export to Excel
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Set to
trueto 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.
-
A message to be shown when Export feature is performing export.
-
A message to be shown when export is almost done.
-
URL of the print server.
-
Config for exporter.
-
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
@pagestyle 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
trueto show column headers on every page. This will also set alignRows to true. Only applies to MultiPageVertical exporter. -
Set to
trueto receive binary file from the server instead of download link. -
Set to
falseto not show Toast message on export error. -
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 requesttrue- stream pages directly to the servernull(default) - ask export server for WebSocket support and use it if possibleHas a corresponding runtime webSocketAvailable property.
-
Maximum time in ms to wait for the response over the websocket connection
Has a corresponding runtime webSocketRequestTimeout property.
-
Format of the exported file, either
pdforpng. -
Name of the exported file.
-
Orientation. Options are
portraitandlandscape. -
Export paper format. Available options are A1...A5, Legal, Letter.
-
Specifies which rows to export.
allfor complete set of rows,visiblefor only rows currently visible.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of PdfExport class, or subclass thereof.
-
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.
-
This yields
trueif 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 requesttrue- stream pages directly to the servernull(default) - ask export server for WebSocket support and use it if possibleHas a corresponding webSocketAvailable config.
-
Maximum time in ms to wait for the response over the websocket connection
Has a corresponding webSocketRequestTimeout config.
-
Identifies an object as an instance of PdfExport class, or subclass thereof.
Functions
Functions are methods available for calling on the class-
Shows export dialog