parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.API.__acroform__.getBit

Error message

Invalid arguments passed to jsPDF.API.__acroform__.getBit

What it means

Thrown by the AcroForm getBit(number, bitPosition) helper when either argument is NaN. getBit reads a single bit and returns 0 or 1; it is exposed at jsPDF.API.__acroform__.getBit. Unlike set/clearBit it does not default the args to 0, so passing undefined directly produces NaN and triggers the throw.

Source

Thrown at src/modules/acroform.js:113

var clearBit = (jsPDFAPI.__acroform__.clearBit = function(number, bitPosition) {
  number = number || 0;
  bitPosition = bitPosition || 0;

  if (isNaN(number) || isNaN(bitPosition)) {
    throw new Error(
      "Invalid arguments passed to jsPDF.API.__acroform__.clearBit"
    );
  }
  var bitMask = 1 << bitPosition;

  number &= ~bitMask;

  return number;
});

var getBit = (jsPDFAPI.__acroform__.getBit = function(number, bitPosition) {
  if (isNaN(number) || isNaN(bitPosition)) {
    throw new Error(
      "Invalid arguments passed to jsPDF.API.__acroform__.getBit"
    );
  }
  return (number & (1 << bitPosition)) === 0 ? 0 : 1;
});

/*
 * Ff starts counting the bit position at 1 and not like javascript at 0
 */
var getBitForPdf = (jsPDFAPI.__acroform__.getBitForPdf = function(
  number,
  bitPosition
) {
  if (isNaN(number) || isNaN(bitPosition)) {
    throw new Error(
      "Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf"
    );
  }

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Pass only finite numbers to getBit; default the value to 0 if unknown.
  2. Ensure F/Ff are initialized to numeric values before any flag read.
  3. Use getBitForPdf with validated positions (1-based).

Example fix

// before
var on = jsPDF.API.__acroform__.getBit(field.F, undefinedPos);

// after
var pos = Number(undefinedPos);
var on = isFinite(pos) ? jsPDF.API.__acroform__.getBit(field.F || 0, pos) : 0;
Defensive patterns

Strategy: type-guard

Validate before calling

function safeGetBit(number, bitPosition) {
  number = Number(number) || 0;
  if (!isFinite(Number(bitPosition))) return 0;
  return jsPDF.API.__acroform__.getBit(number, Number(bitPosition));
}

Type guard

function areFiniteNumbers(a, b) {
  return typeof a === 'number' && isFinite(a) &&
         typeof b === 'number' && isFinite(b);
}

Try / catch

try {
  return jsPDF.API.__acroform__.getBit(val, pos);
} catch (e) {
  if (/__acroform__.getBit/.test(e.message)) return 0;
  throw e;
}

Prevention

When it happens

Trigger: Calling getBit(undefined, pos) or getBit(number, undefined); reading a boolean AcroForm property (e.g. via getBitForPdf, which delegates here) when the flag value or position is NaN.

Common situations: Querying field flags before they are initialized; passing a position computed from a missing config value.

Related errors


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