mozilla/pdf.js · error · FormatError

No shading object found

Error message

No shading object found

What it means

FormatError thrown when shadingFill names a shading that does not exist in the Shading resource dictionary. A Shading resource is present, but the specific name (args[0].name) is not a key in it.

Source

Thrown at src/core/evaluator.js:2135

            }
            if (!isNumberArray(args, null)) {
              continue;
            }
            args = [cs.getRgbHex(args, 0)];
            fn = OPS.setStrokeRGBColor;
            break;

          case OPS.shadingFill:
            let shading;
            try {
              const shadingRes = resources.get("Shading");
              if (!shadingRes) {
                throw new FormatError("No shading resource found");
              }

              shading = shadingRes.get(args[0].name);
              if (!shading) {
                throw new FormatError("No shading object found");
              }
            } catch (reason) {
              if (reason instanceof AbortException) {
                continue;
              }
              if (self.options.ignoreErrors) {
                warn(`getOperatorList - ignoring Shading: "${reason}".`);
                continue;
              }
              throw reason;
            }
            const patternId = self.parseShading({
              shading,
              resources,
              localColorSpaceCache,
              localShadingPatternCache,
            });
            if (!patternId) {

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Enable ignoreErrors: true so the dangling shading reference is skipped.
  2. Repair the PDF: add the named shading entry to the Shading dictionary or correct the name.
  3. Upgrade PDF.js.

Example fix

// before
getDocument({ data }); // missing named shading aborts

// after
getDocument({ data, ignoreErrors: true }); // missing shading skipped
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await page.render({ canvasContext, viewport }).promise;
} catch (e) {
  if (/No shading object found/.test(e.message)) {
    await reloadWith({ ignoreErrors: true });
  } else throw e;
}

Prevention

When it happens

Trigger: shadingFill references shading name X, but shadingRes.get(X) returns nothing (typo, removed entry, or name from a different resource scope).

Common situations: Renamed shading entries, partial resource merging, or generators that emit a shading name without the matching Shading dict entry.

Related errors


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