mozilla/pdf.js · warning · FormatError

Unsupported paint type: ${paintType}

Error message

Unsupported paint type: ${paintType}

What it means

Thrown as a FormatError by TilingPattern when paintType is neither PaintType.COLORED (1) nor PaintType.UNCOLORED (2). It is raised while setting up a tiling pattern's colors, so only the two PDF-spec paint types are valid. Because it is a FormatError (not a plain Error), PDF.js treats it as a recoverable, per-object rendering degradation rather than a fatal crash.

Source

Thrown at src/display/pattern_helper.js:895

  }

  setFillAndStrokeStyleToContext(graphics, paintType, color) {
    const context = graphics.ctx,
      current = graphics.current;
    current.patternFill = current.patternStroke = false;
    switch (paintType) {
      case PaintType.COLORED:
        const { fillStyle, strokeStyle } = this.ctx;
        context.fillStyle = current.fillColor = fillStyle;
        context.strokeStyle = current.strokeColor = strokeStyle;
        break;
      case PaintType.UNCOLORED:
        context.fillStyle = context.strokeStyle = color;
        // Set color needed by image masks (fixes issues 3226 and 8741).
        current.fillColor = current.strokeColor = color;
        break;
      default:
        throw new FormatError(`Unsupported paint type: ${paintType}`);
    }
  }

  isModifyingCurrentTransform() {
    return false;
  }

  getPattern(ctx, owner, inverse, pathType, opIdx) {
    // PDF spec 8.7.2: prepend inverse CTM to patternBaseMatrix to position
    // the CSS pattern.
    const matrix =
      pathType !== PathType.SHADING
        ? Util.transform(inverse, this.patternBaseMatrix)
        : inverse;

    const temporaryPatternCanvas = this.createPatternCanvas(owner, opIdx);

    let domMatrix = new DOMMatrix(matrix);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Update PDF.js; rendering tolerance improves over releases.
  2. Catch rendering errors per page/object so the rest of the document renders.
  3. Report the PDF to the PDF.js project.
  4. If you control the PDF, regenerate it so patterns use paintType 1 or 2.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await page.render({ canvasContext }).promise;
} catch (e) {
  if (e instanceof FormatError && /Unsupported paint type/.test(e.message)) {
    // degrade: continue rendering without this pattern
  }
}

Prevention

When it happens

Trigger: A PDF tiling pattern carries a paintType other than 1 or 2; the pattern setup switch hits the default branch.

Common situations: A malformed or non-standard PDF; a pattern stream corrupted in transit; an edge case in a producer tool.

Related errors


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