parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.lines

Error message

Invalid arguments passed to jsPDF.lines

What it means

Thrown by jsPDF.lines when x or y is NaN, lines is not an array, scale is not an array, the style is invalid, or closed is not a boolean. isValidStyle governs the style argument; valid styles are undefined, null, 'S', 'D', 'F', 'DF', 'FD', 'f', 'f*', 'B', 'B*', 'n'.

Source

Thrown at src/jspdf.js:4607

    if (typeof lines === "number") {
      tmp = y;
      y = x;
      x = lines;
      lines = tmp;
    }

    scale = scale || [1, 1];
    closed = closed || false;

    if (
      isNaN(x) ||
      isNaN(y) ||
      !Array.isArray(lines) ||
      !Array.isArray(scale) ||
      !isValidStyle(style) ||
      typeof closed !== "boolean"
    ) {
      throw new Error("Invalid arguments passed to jsPDF.lines");
    }

    // starting point
    moveTo(x, y);

    scalex = scale[0];
    scaley = scale[1];
    l = lines.length;
    //, x2, y2 // bezier only. In page default measurement "units", *after* scaling
    //, x3, y3 // bezier only. In page default measurement "units", *after* scaling
    // ending point for all, lines and bezier. . In page default measurement "units", *after* scaling
    x4 = x; // last / ending point = starting point for first item.
    y4 = y; // last / ending point = starting point for first item.

    for (i = 0; i < l; i++) {
      leg = lines[i];
      if (leg.length === 2) {
        // simple line

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Pass lines as an array of vector arrays, e.g. [[dx, dy], [dx, dy, cx1, cy1, cx2, cy2, ex, ey]].
  2. Pass scale as an array [sx, sy] (defaults to [1,1]) and closed as a boolean.
  3. Use a valid style code or null/undefined.

Example fix

// before
pdf.lines([10, 10, 20, 20], x, y, 1, 'stroke', true); // flat array + bad style + scale not array
// after
pdf.lines([[10, 10], [20, 20]], x, y, [1, 1], 'S', true);
Defensive patterns

Strategy: validation

Validate before calling

const VALID_STYLES = [undefined, null, 'S','D','F','DF','FD','f','f*','B','B*','n'];
function safeLines(doc, lines, x, y, scale, style, closed) {
  if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error('x,y must be finite');
  if (!Array.isArray(lines) || !Array.isArray(scale || (scale = [1,1]))) throw new Error('lines and scale must be arrays');
  if (typeof closed !== 'boolean') closed = !!closed;
  return doc.lines(lines, x, y, scale, VALID_STYLES.includes(style) ? style : 'S', closed);
}

Type guard

function isValidStyle(s) { return [undefined,null,'S','D','F','DF','FD','f','f*','B','B*','n'].includes(s); }

Prevention

When it happens

Trigger: Calling lines() with a non-array for the path (e.g. an object), scale omitted and not defaulting to an array, a bad style string, or closed passed as a truthy non-boolean (rare, since typeof !== 'boolean' is checked).

Common situations: Passing the bezier vectors as a flat array instead of an array of arrays; forgetting scale defaults; using 'stroke'/'fill' instead of 'S'/'F'; closed given as 0/1 instead of false/true.

Related errors


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