mozilla/pdf.js · warning · Error

Invalid cFunction in AFSimple

Error message

Invalid cFunction in AFSimple

What it means

Thrown by AFSimple when cFunction is not one of AVG, SUM, PRD, MIN, or MAX. After validating both numeric operands, the function switches on the operation name and hits the default branch for any unrecognized operation. It is a content/script error from the PDF's form logic, not an API-misuse error by the embedding app.

Source

Thrown at src/scripting_api/aform.js:363

    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");
  }

  AFSimple_Calculate(cFunction, cFields) {
    const actions = {
      AVG: args => Math.sumPrecise(args) / args.length,
      SUM: args => Math.sumPrecise(args),
      PRD: args => args.reduce((acc, value) => acc * value, 1),
      MIN: args => Math.min(...args),
      MAX: args => Math.max(...args),
    };

    if (!(cFunction in actions)) {
      throw new TypeError("Invalid function in AFSimple_Calculate");
    }

    const event = globalThis.event;
    const values = [];

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair or report the PDF form script.
  2. Update PDF.js; additional operations may be supported over time.
  3. Tolerate scripting failures at the embedding level so the form stays usable.
  4. If authoring the PDF, use only AVG/SUM/PRD/MIN/MAX.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await runFormScript(...);
} catch (e) {
  if (/Invalid cFunction in AFSimple/.test(e.message)) { /* unsupported op; skip */ }
}

Prevention

When it happens

Trigger: A PDF form script calls AFSimple('UNKNOWN', v1, v2) where the operation is not in the supported set.

Common situations: A typo or unsupported operation in the form script; an authoring tool emitting a non-standard cFunction.

Related errors


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