{"record":{"id":"443823f7e9136b76","repo":"parallax/jsPDF","slug":"invalid-argument-passed-to-jspdf-scale","errorCode":null,"errorMessage":"Invalid argument passed to jsPDF.scale","messagePattern":"Invalid argument passed to jsPDF\\.scale","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/jspdf.js","lineNumber":543,"sourceCode":"    };\n  }\n  var f2 = (API.f2 = API.__private__.f2 = function(number) {\n    if (isNaN(number)) {\n      throw new Error(\"Invalid argument passed to jsPDF.f2\");\n    }\n    return roundToPrecision(number, 2);\n  });\n\n  var f3 = (API.__private__.f3 = function(number) {\n    if (isNaN(number)) {\n      throw new Error(\"Invalid argument passed to jsPDF.f3\");\n    }\n    return roundToPrecision(number, 3);\n  });\n\n  var scale = (API.scale = API.__private__.scale = function(number) {\n    if (isNaN(number)) {\n      throw new Error(\"Invalid argument passed to jsPDF.scale\");\n    }\n    if (apiMode === ApiMode.COMPAT) {\n      return number * scaleFactor;\n    } else if (apiMode === ApiMode.ADVANCED) {\n      return number;\n    }\n  });\n\n  var transformY = function(y) {\n    if (apiMode === ApiMode.COMPAT) {\n      return getPageHeight() - y;\n    } else if (apiMode === ApiMode.ADVANCED) {\n      return y;\n    }\n  };\n\n  var transformScaleY = function(y) {\n    return scale(transformY(y));","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/jspdf.js#L525-L561","documentation":"`scale` (src/jspdf.js:541) multiplies a number by the unit scaleFactor in compat mode, or returns it unchanged in advanced mode. It throws at src/jspdf.js:543 if the value is NaN. scale is exposed as `API.scale` and is the bridge between user units (mm, pt, in) and PDF units, so a NaN here means a non-finite measurement was passed into a coordinate/size that the library then scaled.","triggerScenarios":"Calling any positional drawing API with a NaN coordinate/size while in compat mode (scaleFactor is applied); directly invoking `doc.scale(NaN)`; passing a NaN that survives into a coordinate transformation.","commonSituations":"Unit conversion helpers that divide by zero; reading a numeric CSS value (e.g. via getComputedStyle on a hidden element) returning NaN; computing page-relative offsets from a measurement that failed.","solutions":["Find the NaN among the numeric arguments to the failing call.","Validate measurements at the source (DOM reads, data parsing) with `Number.isFinite`.","Default non-finite values to 0 or skip the drawing operation.","When doing manual unit math, guard divisors and parseFloat results."],"exampleFix":"// before\n var widthInPt = px / 0;          // NaN\n doc.rect(0, 0, widthInPt, 100);\n\n// after\n var widthInPt = Number.isFinite(px / dpi) ? px / dpi : 0;\n doc.rect(0, 0, widthInPt, 100);","handlingStrategy":"validation","validationCode":"function finiteNum(x) { return Number.isFinite(x) ? x : 0; }\n// guard unit conversions and DOM-derived measurements:\nvar widthPx = Number.isFinite(parseFloat(style.width)) ? parseFloat(style.width) : 0;\nvar widthPt = finiteNum(widthPx / dpi);\ndoc.rect(0, 0, widthPt, 100);","typeGuard":"function isFiniteNumber(x) { return typeof x === 'number' && Number.isFinite(x); }","tryCatchPattern":"try {\n  doc.rect(0, 0, w, h);\n} catch (e) {\n  if (/jsPDF\\.scale/.test(e.message)) {\n    doc.rect(0, 0, finiteNum(w), finiteNum(h));\n  } else throw e;\n}","preventionTips":["Guard divisors in unit conversions (never divide by zero).","Validate DOM/computed-style measurements with Number.isFinite.","Coerce all sizes/coordinates to finite values before jsPDF calls."],"tags":["numeric","scale","nan","units","geometry"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}