parallax/jsPDF · error · Error
Invalid arguments passed to jsPDF.API.__acroform__.getBitFor
Error message
Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf
What it means
Thrown by getBitForPdf(number, bitPosition) when either argument is NaN. PDF field flags count bit positions starting at 1 (per the PDF spec), so getBitForPdf validates inputs then delegates to getBit with bitPosition-1. Exposed at jsPDF.API.__acroform__.getBitForPdf.
Source
Thrown at src/modules/acroform.js:128
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"
);
}
return getBit(number, bitPosition - 1);
});
var setBitForPdf = (jsPDFAPI.__acroform__.setBitForPdf = function(
number,
bitPosition
) {
if (isNaN(number) || isNaN(bitPosition)) {
throw new Error(
"Invalid arguments passed to jsPDF.API.__acroform__.setBitForPdf"
);
}
return setBit(number, bitPosition - 1);
});
View on GitHub (pinned to a3930ce03a)
Solutions
- Validate number and bitPosition are finite numbers (bitPosition >= 1) before calling getBitForPdf.
- Keep F/Ff numeric so the 'number' argument is never NaN.
- Prefer the high-level boolean properties, which manage positions, over raw helper calls.
Example fix
// before var printed = jsPDF.API.__acroform__.getBitForPdf(field.F, opts.pos); // after var pos = Number(opts.pos); var printed = isFinite(pos) && pos >= 1 ? jsPDF.API.__acroform__.getBitForPdf(field.F || 0, pos) : 0;
Defensive patterns
Strategy: type-guard
Validate before calling
function safeGetBitForPdf(number, bitPosition) {
number = Number(number) || 0;
var p = Number(bitPosition);
if (!isFinite(p) || p < 1) return 0;
return jsPDF.API.__acroform__.getBitForPdf(number, p);
} Type guard
function areFiniteNumbers(a, b) {
return typeof a === 'number' && isFinite(a) &&
typeof b === 'number' && isFinite(b) && b >= 1;
} Try / catch
try {
return jsPDF.API.__acroform__.getBitForPdf(val, pos);
} catch (e) {
if (/__acroform__.getBitForPdf/.test(e.message)) return 0;
throw e;
} Prevention
- Pass 1-based PDF positions only (>= 1).
- Keep F/Ff numeric so the number argument is never NaN.
- Prefer boolean property getters over direct getBitForPdf calls.
When it happens
Trigger: Calling getBitForPdf with NaN number or position; reading a 1-based PDF flag attribute whose underlying _F/_Ff is NaN, or whose position is derived from a missing value.
Common situations: Reading AcroForm boolean getters (many use getBitForPdf internally) after the flag field was corrupted; calling the helper directly with unvalidated parameters.
Related errors
- Invalid arguments passed to jsPDF.API.__acroform__.setBit
- Invalid arguments passed to jsPDF.API.__acroform__.clearBit
- Invalid arguments passed to jsPDF.API.__acroform__.getBit
- 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/3e270c8ff719e6d1.
Report an issue: GitHub.