{hero}

pdf

Since: Buttons 1.0.0

Create and save a PDF file that contains the data from the table.
Please note - this property requires the Buttons extension for DataTables.

Description

This button type serves as a proxy that will automatically detect if the pdfHtml5 button can be used based on the browser's capabilities and the libraries available on the page.

This is provided as an option since the HTML5 button type requires a reasonably modern browser which may not always be available to the end user.

If the requirements of the pdfHtml5 button are not satisfied, no button will be presented to the end user. For the requirements of each button type, please refer to its own documentation.

Options

This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text):

action

Create and save a PDF file.

className

  • Type: string
  • Default: buttons-pdf

The button's class name. See buttons.buttons.className for details.

customize

A function that can be used to customise the PDFMake document definition object for the pdfHtml5 button. The document object is passed in as the first parameter to this function and should be manipulated as required. A return value is not expected or used.

Please refer to the PDFMake documentation for information on how to manipulate this object and the options available for the generated PDF.

As of Buttons 1.5.2 this function is passed three parameters:

  1. An object containing the PDFMake document structure.
  2. The button configuration object
  3. A DataTables API instance for the table the button belongs to.

exportOptions

Select the data to be gathered from the DataTable for export. This includes options for which columns, rows, ordering and search. Please see the buttons.exportData() method for full details - the object given by this parameter is passed directly into that action to gather the required data.

extension

The extension to give the created file name.

filename

File name to give the created file (plus the extension defined by the extension option). The special character * is automatically replaced with the value read from the host document's title tag.

footer

Indicate if the table footer should be included in the exported data or not. Please note that the default for this parameter was updated in Buttons 3.0.1 to be true. In earlier versions it was false.

header

Indicate if the table header should be included in the exported data or not.

message

Optional description message that will be shown above the table in the created PDF. Please note that this option is now deprecated in favour of themessageTop` option.

messageBottom

Message to be shown at the bottom of the table, or the caption tag if displayed at the bottom of the table.

messageTop

Message to be shown at the top of the table, or the caption tag if displayed at the top of the table.

orientation

  • Type: string
  • Default: portrait

Paper orientation for the created PDF. This can be portrait or landscape.

pageSize

Paper size for the created PDF. This can be A3, A4, A5, LEGAL, LETTER or TABLOID.

text

The button's display text. The text can be configured using this option (see buttons.buttons.text) or the buttons.copy option of the DataTables language object.

title

Document title (appears above the table in the generated PDF). The special character * is automatically replaced with the value read from the host document's title tag.

Examples

DataTables initialisation: Use the pdf button type to alias the HTML button options.:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: ['pdf']
		}
	}
});

DataTables initialisation: Use the exportOptions to save only the data shown on the current DataTable page:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'pdf',
					text: 'Save current page',
					exportOptions: {
						modifier: {
							page: 'current'
						}
					}
				}
			]
		}
	}
});