mozilla/pdf.js · error · Error
Images with ${image.numComps} color components not supported
Error message
Images with ${image.numComps} color components not supported. What it means
Thrown when an image has no explicit ColorSpace and is not a JPX/JPEG2000 image, but its number of color components (numComps) is not 1, 3, or 4. PDF.js infers DeviceGray/RGB/CMYK only for those counts; any other count cannot be mapped to a default device space.
Source
Thrown at src/core/image.js:233
}
}
if (!hasColorSpace) {
if (this.jpxDecoderOptions) {
colorSpace = Name.get("DeviceRGBA");
} else {
switch (image.numComps) {
case 1:
colorSpace = Name.get("DeviceGray");
break;
case 3:
colorSpace = Name.get("DeviceRGB");
break;
case 4:
colorSpace = Name.get("DeviceCMYK");
break;
default:
throw new Error(
`Images with ${image.numComps} color components not supported.`
);
}
}
} else if (this.jpxDecoderOptions?.smaskInData) {
// If the jpx image has a color space then it mustn't be used in order
// to be able to use the color space that comes from the pdf.
colorSpace = Name.get("DeviceRGBA");
}
this.colorSpace = ColorSpaceUtils.parse({
cs: colorSpace,
xref,
resources: isInline ? res : null,
pdfFunctionFactory,
globalColorSpaceCache,
localColorSpaceCache,
});View on GitHub (pinned to 5903d58d58)
Solutions
- When generating PDFs, always attach an explicit /ColorSpace to images whose component count is not 1/3/4.
- Convert the source image to Gray/RGB/CMYK before embedding.
- Catch the Error at render time and skip the image.
- If the image is JPEG2000, ensure jpx decoder options are configured so pdf.js takes the JPX branch.
Defensive patterns
Strategy: validation
Validate before calling
// For images you author, map component counts to a ColorSpace explicitly:
function defaultColorSpaceForComponents(numComps) {
switch (numComps) {
case 1: return 'DeviceGray';
case 3: return 'DeviceRGB';
case 4: return 'DeviceCMYK';
default: return null; // must specify ColorSpace explicitly
}
} Type guard
function isInferableComponentCount(n) {
return n === 1 || n === 3 || n === 4;
} Try / catch
try { await page.render({ canvasContext }).promise; }
catch (err) {
if (/color components not supported/.test(err?.message || '')) {
console.warn('Image has unsupported component count; skipping.');
} else throw err;
} Prevention
- Always attach an explicit /ColorSpace to non-standard-channel images.
- Pre-convert images to Gray/RGB/CMYK before embedding.
- Render per-page in try/catch to isolate failures.
When it happens
Trigger: An image stream with numComps of e.g. 2 or 5, no /ColorSpace, and not handled by jpxDecoderOptions. Reached while rendering such an image's XObject or inline form.
Common situations: Multi-channel or specialized images embedded without a ColorSpace; images whose component count was misreported by a damaged decoder; non-JP2 images that should have declared an Indexed or DeviceN space.
Related errors
- Unable to decode inline image: "${reason}".
- Unsupported number of components: ${numComps}
- Invalid image width: ${width} or height: ${height}
- Bits per component missing in image: ${this.imageMask}
- Unknown mask format.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/4d202ea1f0479f46.
Report an issue: GitHub.