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.pageIndexView on GitHub (pinned to 5903d58d58)
Solutions
- Enable ignoreErrors: true in getDocument so the bad inline image is dropped with a warning instead of failing the whole page.
- Upgrade PDF.js, since image-decoding fixes land frequently.
- Repair or re-export the PDF from a tool that re-encodes inline images.
- 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
- Set ignoreErrors:true when rendering untrusted user-uploaded PDFs.
- Keep PDF.js current; inline-image decoding fixes ship regularly.
- Log the failing page number so corrupt source PDFs can be re-exported.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Image exceeded maximum allowed size and was removed.
- Unknown PatternType: ${typeNum}
- Unknown PatternName: ${patternName}
- getOperatorList - ignoring circular reference: ${objId}
- XObject must be referred to by name.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/7ae5e7e760f625a8.
Report an issue: GitHub.