mozilla/pdf.js · warning · Error

Invalid psf in AFSpecial_Format

Error message

Invalid psf in AFSpecial_Format

What it means

Thrown by AFSpecial_Format when the psf (special-format) selector is not 0 (zip), 1 (zip+4), 2 (phone), or 3 (SSN). The function builds a mask string per known format and rejects anything else via the default branch. It runs inside the sandboxed PDF-JS form environment invoked by the PDF.

Source

Thrown at src/scripting_api/aform.js:429

    let formatStr;
    switch (psf) {
      case 0:
        formatStr = "99999";
        break;
      case 1:
        formatStr = "99999-9999";
        break;
      case 2:
        formatStr =
          this._util.printx("9999999999", event.value).length >= 10
            ? "(999) 999-9999"
            : "999-9999";
        break;
      case 3:
        formatStr = "999-99-9999";
        break;
      default:
        throw new Error("Invalid psf in AFSpecial_Format");
    }

    event.value = this._util.printx(formatStr, event.value);
  }

  AFSpecial_KeystrokeEx(cMask) {
    const event = globalThis.event;

    // Simplify the format string by removing all characters that are not
    // specific to the format because the user could enter 1234567 when the
    // format is 999-9999.
    const simplifiedFormatStr = cMask.replaceAll(/[^9AOX]/g, "");
    this.#AFSpecial_KeystrokeEx_helper(simplifiedFormatStr, null, false);
    if (event.rc) {
      return;
    }

    event.rc = true;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair or report the PDF form script; the error is content-driven.
  2. Update PDF.js for any improved tolerance.
  3. Ensure the embedding app degrades gracefully when formatting throws.
  4. If authoring the PDF, use psf in 0..3.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await runFormScript(...);
} catch (e) {
  if (/Invalid psf in AFSpecial_Format/.test(e.message)) { /* skip formatting */ }
}

Prevention

When it happens

Trigger: A PDF form script calls AFSpecial_Format(psf) with psf outside [0,3].

Common situations: A malformed format specifier in the PDF; an authoring tool emitting a non-standard psf; a calculated psf that falls outside the valid range.

Related errors


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