mozilla/pdf.js · error · FormatError

Unknown PatternType: ${typeNum}

Error message

Unknown PatternType: ${typeNum}

What it means

FormatError thrown by the pattern resolver when a pattern object's PatternType is neither TILING (1) nor SHADING (2) as defined in the PDF spec. It signals a non-standard or corrupt pattern dictionary.

Source

Thrown at src/core/evaluator.js:1664

            task,
            localTilingPatternCache,
            seenRefs
          );
        } else if (typeNum === PatternType.SHADING) {
          const shading = dict.get("Shading");
          const objId = this.parseShading({
            shading,
            resources,
            localColorSpaceCache,
            localShadingPatternCache,
          });
          if (objId) {
            const matrix = lookupMatrix(dict.getArray("Matrix"), null);
            operatorList.addOp(fn, ["Shading", objId, matrix]);
          }
          return undefined;
        }
        throw new FormatError(`Unknown PatternType: ${typeNum}`);
      }
    }
    throw new FormatError(`Unknown PatternName: ${patternName}`);
  }

  async parseMarkedContentProps(contentProperties, resources) {
    return parseMarkedContentProps(this.xref, contentProperties, resources);
  }

  async getOperatorList({
    stream,
    task,
    resources,
    operatorList,
    initialState = null,
    fallbackFontDict = null,
    prevRefs = null,
  }) {

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Enable ignoreErrors: true so the unknown pattern is skipped and the page renders without it.
  2. Repair the PDF: correct or remove the offending PatternType entry.
  3. Upgrade PDF.js in case newer spec-allowed values are supported.

Example fix

// before
getDocument({ data }); // render aborts on unknown PatternType

// after
getDocument({ data, ignoreErrors: true }); // pattern skipped, page renders
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await page.render({ canvasContext, viewport }).promise;
} catch (e) {
  if (/Unknown PatternType/.test(e.message)) {
    await reloadWith({ ignoreErrors: true }); // unknown pattern skipped
  } else throw e;
}

Prevention

When it happens

Trigger: A setFillColorN/setStrokeColorN color operator references a pattern whose resolved dictionary has a PatternType value other than 1 or 2 (e.g. 0, 3, missing, or a non-integer). The error propagates through the color-handling case of getOperatorList; with ignoreErrors true it becomes a warning.

Common situations: Malformed PDFs, obscure generators, or PDFs whose pattern dict was truncated. Rare in well-formed documents.

Related errors


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