Export to PDF

index

Description

You can Export to PDF, which will create a PDF file using the jsPDFarrow-up-right library. This is an opt-in Service: you must download @slickgrid-universal/pdf-export and instantiate it in your grid options via externalResources.

Demo

Demo Pagearrow-up-right / Demo Componentarrow-up-right

Grid Menu (hamburger menu)

The Grid Menu can include an "Export to PDF" command. You can show/hide this option with hideExportPdfCommand (defaults to false).

Grid Options

You can set options for the entire grid, such as enabling PDF export and customizing export behavior.

Column Definition and Options

  • excludeFromExport: skip this column in the export

  • exportWithFormatter: use the column's formatter for export (column-level overrides grid option)

  • exportCustomFormatter: use a different formatter for export

  • sanitizeDataExport: remove HTML/script from exported data

  • pdfExportOptions: per-column PDF export options (see interface for details)

You can add a custom header or footer to your PDF using the documentTitle option or by customizing the export logic.

Styling the PDF

You can customize font size, orientation, margins, and more via pdfExportOptions:

Simulating PDF Zoom / Fit More Columns

jsPDF does not have a true "zoom" feature, but you can fit more columns or make the export appear smaller by reducing the font size and/or column widths in your pdfExportOptions. For example, setting fontSize and headerFontSize to 80% of their defaults will make the content appear "zoomed out" and fit more columns on the page:

You can also use pageOrientation: 'landscape' or a larger pageSize to fit more content horizontally.

Grouped Column Headers

If your grid uses column grouping, you can enable pre-header rows in the PDF export:

Export from a Button Click Event

You can export from the Grid Menu or trigger export from your own button:

Show Loading Process Spinner

You can subscribe to onBeforeExportToPdf and onAfterExportToPdf events to show/hide a spinner during export.

UI Sample

The Export to PDF supports Unicode, custom formatting, and grouped headers. See the demo for a preview.


For more advanced options, see the pdfExportOption.interface.tsarrow-up-right.

Last updated