mozilla/pdf.js · warning · Error
Invalid nValue1 in AFSimple
Error message
Invalid nValue1 in AFSimple
What it means
Thrown by AFSimple when AFMakeNumber(nValue1) returns null, i.e. nValue1 cannot be coerced to a number. AFSimple performs arithmetic (AVG/SUM/PRD/MIN/MAX) and requires both operands to be numeric, so a non-coercible first operand is rejected. It executes within the sandboxed PDF-JS form environment.
Source
Thrown at src/scripting_api/aform.js:342
);
}
} else if (bGreaterThan) {
if (value < nGreaterThan) {
err = this._util.printf(GlobalConstants.IDS_GREATER_THAN, nGreaterThan);
}
} 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);View on GitHub (pinned to 5903d58d58)
Solutions
- Repair or report the PDF form script; the error is content-driven.
- Update PDF.js to benefit from any future coercion leniency.
- Let the embedding app tolerate scripting failures so the rest of the form still works.
- If authoring the PDF, pass numeric values to AFSimple.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await runFormScript(...);
} catch (e) {
if (/Invalid nValue1 in AFSimple/.test(e.message)) { /* skip calculation */ }
} Prevention
- Isolate sandbox scripting errors from the rendering pipeline.
- Repair PDFs whose form scripts pass non-numeric values to AFSimple.
- Update PDF.js for improved coercion.
- Keep forms functional even when a calculation throws.
When it happens
Trigger: A PDF form script calls AFSimple(cFunction, nValue1, nValue2) where nValue1 is a non-numeric, non-coercible value (e.g. an object or unparseable string).
Common situations: A field value is empty or a non-numeric string that AFMakeNumber cannot parse; a malformed form script passes the wrong argument type.
Related errors
- Invalid nValue2 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/816ca1cf0ea6b738.
Report an issue: GitHub.