Class: PDFTable

PDFTable(columns, options)

Initialize a table for outputting to a PDF. Usage:

  let pdfBuilder = new PDFBuilder();
  let table = new PDFTable();
  pdfBuilder.addTable()

Minimum options required to build out the table:

  let table = new PDFTable([{
    header: { text: 'ID' },
    rows:  [{ text: '1' }, { text: '2' }, { text: '3' }]
  }, {
    header: { text: 'Name' },
    rows:  [{ text: 'Billy' }, { text: 'Bob' }, { text: 'Suzy' }]
  }]);

All available options:

  let table = new PDFTable([{
    header: {
      align:       'center',
      borderColor: '#000',
      borderStyle: 'bottom',
      borderWidth: 2,
      color:       '#000',
      font:        'Helvetica-Bold',
      fontSize:    14,
      text:        'Name'
    },
    rows: [{
      align:       'center',
      borderColor: '#000',
      borderStyle: 'bottom',
      borderWidth: 2,
      color:       '#000',
      font:        'Helvetica-Bold',
      fontSize:    14,
      text:        'Brian'
    }],
    width: 150 // or 0.25 for 25% of the table's width
  }]);

Constructor

new PDFTable(columns, options)

Parameters:
Name Type Description
columns Array

Columns for the table

options Object

Options for formatting and styling the table

Properties
Name Type Default Description
cellAlign string left

Align text in the cell

cellAllowWrap boolean false

Allow cell wrapping

cellBorderWidth number 1

Cell border width

cellColor string #222

Cell text color

cellEmptyColor string #FFFFFF

Empty cell color

cellEmptyText string none

Empty cell text content

cellFont string Helvetica

Cell font style

cellFontSize number 14

Cell font size

cellItalic boolean false

Cell is italicized

headerAllowWrap boolean false

Allow the header to wrap

headerAlign string left

Align text in the row header

headerColor string #000

Row header text color

margins Margin

Table margins

Source:

Methods

addToPDF(builder)

Add a table to the PDF document.

Parameters:
Name Type Description
builder PDFBuilder
Source:

width() → {number}

Returns the full width of the table based on the page size and margins.

Source:
Returns:
Type
number