mozilla/pdf.js · warning · Error
Invalid nValue2 in AFSimple
Error message
Invalid nValue2 in AFSimple
What it means
Thrown by AFSimple when AFMakeNumber(nValue2) returns null, i.e. the second operand cannot be coerced to a number. Identical in intent to the nValue1 check: both arithmetic operands must be numeric. Runs inside the sandboxed PDF-JS form environment.
Source
Thrown at src/scripting_api/aform.js:347
}
} else if (value > nLessThan) {
err = this._util.printf(GlobalConstants.IDS_LESS_THAN, nLessThan);
}
if (err) {
this._app.alert(err);
event.rc = false;
}
}
AFSimple(cFunction, nValue1, nValue2) {
const value1 = this.AFMakeNumber(nValue1);
if (value1 === null) {
throw new Error("Invalid nValue1 in AFSimple");
}
const value2 = this.AFMakeNumber(nValue2);
if (value2 === null) {
throw new Error("Invalid nValue2 in AFSimple");
}
switch (cFunction) {
case "AVG":
return (value1 + value2) / 2;
case "SUM":
return value1 + value2;
case "PRD":
return value1 * value2;
case "MIN":
return Math.min(value1, value2);
case "MAX":
return Math.max(value1, value2);
}
throw new Error("Invalid cFunction in AFSimple");
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Repair or report the PDF form script; the error originates in PDF content.
- Update PDF.js for any improved tolerance.
- Ensure the embedding app degrades gracefully on scripting errors.
- If authoring the PDF, pass numeric values for both operands.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await runFormScript(...);
} catch (e) {
if (/Invalid nValue2 in AFSimple/.test(e.message)) { /* skip calculation */ }
} Prevention
- Isolate sandbox scripting errors from rendering.
- Repair PDFs whose form scripts pass non-numeric second operands.
- Update PDF.js for improved coercion.
- Ensure forms stay usable when a calculation fails.
When it happens
Trigger: A PDF form script calls AFSimple(cFunction, nValue1, nValue2) where nValue2 is non-coercible to a number.
Common situations: An empty or non-numeric field value passed as the second operand; a malformed form script.
Related errors
- Invalid nValue1 in AFSimple
- Invalid cFunction in AFSimple
- Invalid function in AFSimple_Calculate
- Invalid nDec value in AFPercent_Format
- Invalid psf in AFSpecial_Format
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/963ae0afb7839dc5.
Report an issue: GitHub.