mozilla/pdf.js · error · Error

Unable to decode inline image: "${reason}".

Error message

Unable to decode inline image: "${reason}".

What it means

Thrown when decoding a small inline image into RGBA fails inside buildPaintImageXObject. The inlining path only runs for tiny images (w+h < 200, no SMask/Mask); any exception from PDFImage construction or createImageData is wrapped into this message. It indicates corrupt or unsupported inline image data.

Source

Thrown at src/core/evaluator.js:770

          globalColorSpaceCache: this.globalColorSpaceCache,
          localColorSpaceCache,
        });
        // We force the use of RGBA_32BPP images here, because we can't handle
        // any other kind.
        imgData = await imageObj.createImageData(
          /* forceRGBA = */ true,
          /* isOffscreenCanvasSupported = */ false
        );
        operatorList.addImageOps(
          OPS.paintInlineImageXObject,
          [imgData],
          optionalContent
        );
      } catch (reason) {
        const msg = `Unable to decode inline image: "${reason}".`;

        if (!ignoreErrors) {
          throw new Error(msg);
        }
        warn(msg);
      }
      return;
    }

    // If there is no imageMask, create the PDFImage and a lot
    // of image processing can be done here.
    let objId = `img_${this.idFactory.createObjId()}`,
      cacheGlobally = false,
      globalCacheData = null;

    if (this.parsingType3Font) {
      objId = `${this.idFactory.getDocId()}_type3_${objId}`;
    } else if (cacheKey && imageRef) {
      cacheGlobally = this.globalImageCache.shouldCache(
        imageRef,
        this.pageIndex

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Enable ignoreErrors: true in getDocument so the bad inline image is dropped with a warning instead of failing the whole page.
  2. Upgrade PDF.js, since image-decoding fixes land frequently.
  3. Repair or re-export the PDF from a tool that re-encodes inline images.
  4. If you control the PDF, replace inline images with standard XObject images.

Example fix

// before
getDocument({ data }); // page render rejects on bad inline image

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

Strategy: try-catch

Try / catch

// Inline-image decode errors originate in the worker and cannot be pre-checked.
// Render defensively and optionally retry with ignoreErrors enabled.
try {
  await page.render({ canvasContext, viewport }).promise;
} catch (e) {
  if (/Unable to decode inline image/.test(e.message)) {
    await reloadWith({ ignoreErrors: true });
  } else throw e;
}

Prevention

When it happens

Trigger: A content stream contains an inline image (BI...ID...EI) with total w+h under 200 and no mask, whose stream data, filter, or color space cannot be decoded, while ignoreErrors is false.

Common situations: Corrupt or truncated PDFs, PDFs produced by buggy generators with malformed inline image filters (e.g. bad Flate/LZW/DCT streams), or rarely-supported color spaces on inline images.

Understand the failure class

Related errors


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