{"record":{"id":"f1012729d0d3fb4f","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform-f10127","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.setBitForPdf","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.setBitForPdf","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":140,"sourceCode":" */\nvar getBitForPdf = (jsPDFAPI.__acroform__.getBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.getBitForPdf\"\n    );\n  }\n  return getBit(number, bitPosition - 1);\n});\n\nvar setBitForPdf = (jsPDFAPI.__acroform__.setBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.setBitForPdf\"\n    );\n  }\n  return setBit(number, bitPosition - 1);\n});\n\nvar clearBitForPdf = (jsPDFAPI.__acroform__.clearBitForPdf = function(\n  number,\n  bitPosition\n) {\n  if (isNaN(number) || isNaN(bitPosition)) {\n    throw new Error(\n      \"Invalid arguments passed to jsPDF.API.__acroform__.clearBitForPdf\"\n    );\n  }\n  return clearBit(number, bitPosition - 1);\n});\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L122-L158","documentation":"Thrown by setBitForPdf(number, bitPosition) when either argument is NaN. This is the 1-based wrapper over setBit (delegates with bitPosition-1) used by AcroForm boolean setters like showWhenPrinted. Exposed at jsPDF.API.__acroform__.setBitForPdf.","triggerScenarios":"Calling setBitForPdf with NaN, or toggling an AcroForm boolean property whose underlying _F flag is NaN (so the 'number' argument is NaN) or whose PDF bit position is missing.","commonSituations":"Setting field.showWhenPrinted or similar after a bad F assignment; programmatic flag building with unvalidated positions.","solutions":["Ensure number (the flag accumulator) and bitPosition are finite numbers, bitPosition >= 1.","Never set F/Ff to non-numeric values before toggling boolean properties.","Use the boolean property setters, which supply correct positions, rather than calling setBitForPdf with a computed index."],"exampleFix":"// before\nfield.showWhenPrinted = true; // _F is NaN -> setBitForPdf throws\n\n// after\nif (typeof field.F === 'number' && !isNaN(field.F)) {\n  field.showWhenPrinted = true;\n}","handlingStrategy":"type-guard","validationCode":"function safeSetBitForPdf(number, bitPosition) {\n  number = Number(number);\n  var p = Number(bitPosition);\n  if (!isFinite(number) || !isFinite(p) || p < 1) {\n    throw new Error('setBitForPdf needs finite number and bitPosition>=1');\n  }\n  return jsPDF.API.__acroform__.setBitForPdf(number, p);\n}","typeGuard":"function areFiniteNumbers(a, b) {\n  return typeof a === 'number' && isFinite(a) &&\n         typeof b === 'number' && isFinite(b) && b >= 1;\n}","tryCatchPattern":"try {\n  field.F = jsPDF.API.__acroform__.setBitForPdf(field.F, pos);\n} catch (e) {\n  if (/__acroform__.setBitForPdf/.test(e.message)) {\n    if (typeof field.F !== 'number' || isNaN(field.F)) field.F = 4;\n    field.F = jsPDF.API.__acroform__.setBitForPdf(field.F, pos);\n  } else throw e;\n}","preventionTips":["Ensure the flag accumulator (F/Ff) is numeric before toggling boolean properties.","Pass only finite, 1-based positions.","Use the boolean property setters which manage positions internally."],"tags":["acroform","validation","bit-ops","internal"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}