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
- Ensure both arguments are finite numbers (coerce with Number() and guard) before calling setBit.
- Never assign non-numeric values to F/Ff on AcroForm fields, since those feed the bit helpers.
- 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
- Never pass undefined/NaN to bit helpers; coerce first.
- Keep F/Ff numeric so downstream setBit calls get valid inputs.
- Prefer the high-level boolean properties over direct setBit calls.
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
- Invalid arguments passed to jsPDF.API.__acroform__.clearBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBitFor
- Invalid arguments passed to jsPDF.API.__acroform__.setBitFor
- Invalid arguments passed to jsPDF.API.__acroform__.clearBitF
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/1e41336de02474d5.
Report an issue: GitHub.