parallax/jsPDF · error · Error

Invalid arguments passed to jsPDF.API.__acroform__.setBit

Error message

Invalid arguments passed to jsPDF.API.__acroform__.setBit

What it means

Thrown by the AcroForm setBit(number, bitPosition) helper when either argument is NaN after coercion. setBit is an internal bit-manipulation utility (exposed at jsPDF.API.__acroform__.setBit) that sets a single bit on an integer field-flag value. It defaults both args to 0, so NaN only occurs when a caller explicitly passes undefined/non-numeric that survives the `|| 0` default (e.g. the literal value NaN, or a string).

Source

Thrown at src/modules/acroform.js:84

};

var createFormXObject = function(formObject) {
  var xobj = new AcroFormXObject();
  var height = AcroFormAppearance.internal.getHeight(formObject) || 0;
  var width = AcroFormAppearance.internal.getWidth(formObject) || 0;
  xobj.BBox = [0, 0, Number(f2(width)), Number(f2(height))];
  return xobj;
};

/**
 * Bit-Operations
 */
var setBit = (jsPDFAPI.__acroform__.setBit = function(number, bitPosition) {
  number = number || 0;
  bitPosition = bitPosition || 0;

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

  number |= bitMask;

  return number;
});

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"
    );

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Ensure both arguments are finite numbers (coerce with Number() and guard) before calling setBit.
  2. Never assign non-numeric values to F/Ff on AcroForm fields, since those feed the bit helpers.
  3. If using the helper directly, sanitize inputs: `setBit(Number(x)||0, Number(p)||0)`.

Example fix

// before
field.F = jsPDF.API.__acroform__.setBit(field.F, maybeUndefined);

// after
var pos = Number(maybeUndefined);
if (isFinite(pos)) {
  field.F = jsPDF.API.__acroform__.setBit(field.F, pos);
}
Defensive patterns

Strategy: type-guard

Validate before calling

function safeSetBit(number, bitPosition) {
  number = Number(number) || 0;
  bitPosition = Number(bitPosition);
  if (!isFinite(bitPosition)) throw new Error('bitPosition must be a finite number');
  return jsPDF.API.__acroform__.setBit(number, bitPosition);
}

Type guard

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

Try / catch

try {
  val = jsPDF.API.__acroform__.setBit(val, pos);
} catch (e) {
  if (/__acroform__.setBit/.test(e.message)) {
    pos = Number(pos) || 0; val = val || 0;
    val = jsPDF.API.__acroform__.setBit(val, pos);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling jsPDF.API.__acroform__.setBit(value, pos) with NaN, or indirectly when an AcroForm boolean property setter (e.g. showWhenPrinted) is toggled while _F/_Ff already became NaN from a previous bad assignment.

Common situations: Programmatically building AcroForm fields and passing a non-numeric flag accumulator; a prior isNaN failure leaving a flag field as NaN that then propagates into setBit.

Related errors


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