parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.text

Error message

Invalid arguments passed to jsPDF.text

What it means

Thrown by jsPDF.text when x or y is NaN, or when text is undefined/null. The guard is `isNaN(x) || isNaN(y) || typeof text === 'undefined' || text === null`. Coordinates must be finite numbers and text must be a defined, non-null value (string or array).

Source

Thrown at src/jspdf.js:3554

        if (typeof flags === "number") {
          angle = flags;
          flags = null;
        }
        options = {
          flags: flags,
          angle: angle,
          align: align
        };
      }
    } else {
      advancedApiModeTrap(
        "The transform parameter of text() with a Matrix value"
      );
      transformationMatrix = transform;
    }

    if (isNaN(x) || isNaN(y) || typeof text === "undefined" || text === null) {
      throw new Error("Invalid arguments passed to jsPDF.text");
    }

    if (text.length === 0) {
      return scope;
    }

    var xtra = "";
    var isHex = false;
    var lineHeight =
      typeof options.lineHeightFactor === "number"
        ? options.lineHeightFactor
        : lineHeightFactor;
    var scaleFactor = scope.internal.scaleFactor;

    function ESC(s) {
      s = s.split("\t").join(Array(options.TabLen || 9).join(" "));
      return pdfEscape(s, flags);
    }

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Ensure x and y are finite numbers (default missing coordinates to 0 or a computed value).
  2. Guarantee text is a non-null string or array; default to '' when the source value is absent.
  3. Check argument order: jsPDF.text(text, x, y, options).

Example fix

// before
pdf.text(data.label, data.x, data.y); // data.label may be undefined
// after
pdf.text(data.label || '', Number(data.x) || 0, Number(data.y) || 0);
Defensive patterns

Strategy: validation

Validate before calling

function safeText(doc, text, x, y, options) {
  if (text == null) text = '';
  if (typeof text !== 'string' && !Array.isArray(text)) text = String(text);
  if (!Number.isFinite(x) || !Number.isFinite(y)) throw new Error('x and y must be finite numbers');
  return doc.text(text, x, y, options);
}

Type guard

function isValidTextArgs(text, x, y) {
  return (typeof text === 'string' || Array.isArray(text)) && text != null && Number.isFinite(x) && Number.isFinite(y);
}

Prevention

When it happens

Trigger: Calling text(undefined, x, y); text('hi', NaN, 10); text('hi', 10, undefined); passing a coordinate computed from a missing property (undefined -> NaN); forgetting the text argument.

Common situations: Coordinates derived from missing or optional object properties that are undefined; swapped argument order; empty/absent text payload from an API response; defaulting text to undefined instead of ''.

Related errors


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