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

  1. Repair or report the PDF form script; the error originates in PDF content.
  2. Update PDF.js for any improved tolerance.
  3. Ensure the embedding app degrades gracefully on scripting errors.
  4. 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

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


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/963ae0afb7839dc5. Report an issue: GitHub.