parallax/jsPDF · error · Error

No data for PDF table.

Error message

No data for PDF table.

What it means

doc.table() generates a tabular layout in the PDF from an array of row objects. The data parameter is the array of objects where each object's keys are column names and values are cell content. The function checks that data is truthy before proceeding because all subsequent logic (header extraction via Object.keys(data[0]), row iteration, column sizing) depends on having actual row data.

Source

Thrown at src/modules/cell.js:382

     * @param {Object[]} [data] An array of objects containing key-value pairs corresponding to a row of data.
     * @param {String[]} [headers] Omit or null to auto-generate headers at a performance cost

     * @param {Object} [config.printHeaders] True to print column headers at the top of every page
     * @param {Object} [config.autoSize] True to dynamically set the column widths to match the widest cell value
     * @param {Object} [config.margins] margin values for left, top, bottom, and width
     * @param {Object} [config.fontSize] Integer fontSize to use (optional)
     * @param {Object} [config.padding] cell-padding in pt to use (optional)
     * @param {Object} [config.headerBackgroundColor] default is #c8c8c8 (optional)
     * @param {Object} [config.headerTextColor] default is #000 (optional)
     * @param {Object} [config.rowStart] callback to handle before print each row (optional)
     * @param {Object} [config.cellStart] callback to handle before print each cell (optional)
     * @returns {jsPDF} jsPDF-instance
     */

  jsPDFAPI.table = function(x, y, data, headers, config) {
    _initialize.call(this);
    if (!data) {
      throw new Error("No data for PDF table.");
    }

    config = config || {};

    var headerNames = [],
      headerLabels = [],
      headerAligns = [],
      i,
      columnMatrix = {},
      columnWidths = {},
      column,
      columnMinWidths = [],
      j,
      tableHeaderConfigs = [],
      //set up defaults. If a value is provided in config, defaults will be overwritten:
      autoSize = config.autoSize || false,
      printHeaders = config.printHeaders === false ? false : true,
      fontSize =

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Ensure data is at least an empty array: doc.table(x, y, data || [], headers)
  2. Guard the call: if (data && data.length > 0) doc.table(x, y, data, headers)
  3. Initialize data variables to [] instead of null/undefined
  4. For async data, call table() inside the .then() or after await

Example fix

// before
var data = apiResponse.items; // null if no items
doc.table(10, 10, data, headers); // throws

// after
doc.table(10, 10, data || [], headers);
// or guard:
if (data && data.length) doc.table(10, 10, data, headers);
Defensive patterns

Strategy: validation

Validate before calling

// Validate data before calling table
function safeTable(doc, x, y, data, headers, config) {
  if (!data || !Array.isArray(data)) {
    throw new TypeError('data must be a non-null array of row objects');
  }
  return doc.table(x, y, data, headers, config);
}

// Or guard the call
if (data && data.length > 0) {
  doc.table(10, 10, data, headers);
}

Type guard

/**
 * @param {*} data
 * @returns {boolean}
 */
function isValidTableData(data) {
  return Array.isArray(data) && data.length > 0 &&
    data.every(function(row) { return row != null && typeof row === 'object'; });
}

Try / catch

try {
  doc.table(10, 10, data, headers);
} catch (e) {
  if (e.message === 'No data for PDF table.') {
    console.warn('No data available for table - skipping');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling doc.table(x, y, undefined, headers). Passing null when data comes from an empty API response. Passing an empty string or 0 (all falsy values trigger this). Forgetting the third argument. Passing data before an async fetch completes.

Common situations: API responses that return null for empty result sets. Async data loading where table() is called before the data arrives. Conditional rendering where data may be absent. Destructuring that produces undefined when the key doesn't exist.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/dbb7540e829a9a89. Report an issue: GitHub.