{"record":{"id":"110b1c27de60cb4c","repo":"parallax/jsPDF","slug":"invalid-arguments-passed-to-jspdf-api-acroform-110b1c","errorCode":null,"errorMessage":"Invalid arguments passed to jsPDF.API.__acroform__.clearBitForPdf","messagePattern":"Invalid arguments passed to jsPDF\\.API\\.__acroform__\\.clearBitForPdf","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/modules/acroform.js","lineNumber":152,"sourceCode":"\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\nvar calculateCoordinates = (jsPDFAPI.__acroform__.calculateCoordinates = function(\n  args,\n  scope\n) {\n  var getHorizontalCoordinate = scope.internal.getHorizontalCoordinate;\n  var getVerticalCoordinate = scope.internal.getVerticalCoordinate;\n  var x = args[0];\n  var y = args[1];\n  var w = args[2];\n  var h = args[3];\n\n  var coordinates = {};","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/modules/acroform.js#L134-L170","documentation":"Thrown by clearBitForPdf(number, bitPosition) when either argument is NaN. This is the 1-based wrapper over clearBit (delegates with bitPosition-1) used by AcroForm boolean setters to turn a PDF flag bit off. Exposed at jsPDF.API.__acroform__.clearBitForPdf.","triggerScenarios":"Calling clearBitForPdf with NaN, or toggling an AcroForm boolean property to false when the underlying _F/_Ff flag is NaN, or passing an undefined PDF bit position.","commonSituations":"Setting field.showWhenPrinted = false (or other boolean props) after _F became NaN; clearing flags with a position read from missing config.","solutions":["Validate number and bitPosition are finite numbers (bitPosition >= 1) before calling clearBitForPdf.","Keep F/Ff numeric at all times so boolean setters can clear bits safely.","Reset corrupt flag fields to their defaults (F=4, Ff=0) before toggling properties."],"exampleFix":"// before\nfield.showWhenPrinted = false; // _F is NaN -> clearBitForPdf throws\n\n// after\nif (typeof field.F !== 'number' || isNaN(field.F)) field.F = 4;\nfield.showWhenPrinted = false;","handlingStrategy":"type-guard","validationCode":"function safeClearBitForPdf(number, bitPosition) {\n  number = Number(number);\n  var p = Number(bitPosition);\n  if (!isFinite(number) || !isFinite(p) || p < 1) {\n    throw new Error('clearBitForPdf needs finite number and bitPosition>=1');\n  }\n  return jsPDF.API.__acroform__.clearBitForPdf(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__.clearBitForPdf(field.F, pos);\n} catch (e) {\n  if (/__acroform__.clearBitForPdf/.test(e.message)) {\n    if (typeof field.F !== 'number' || isNaN(field.F)) field.F = 4;\n    field.F = jsPDF.API.__acroform__.clearBitForPdf(field.F, pos);\n  } else throw e;\n}","preventionTips":["Keep F/Ff numeric; reset corrupt flags to defaults (F=4, Ff=0).","Pass only finite, 1-based positions to clearBitForPdf.","Prefer boolean property setters over manual bit clearing."],"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"}