{"record":{"id":"4d202ea1f0479f46","repo":"mozilla/pdf.js","slug":"images-with-image-numcomps-color-components-not","errorCode":null,"errorMessage":"Images with ${image.numComps} color components not supported.","messagePattern":"Images with (.+?) color components not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/image.js","lineNumber":233,"sourceCode":"        }\n      }\n\n      if (!hasColorSpace) {\n        if (this.jpxDecoderOptions) {\n          colorSpace = Name.get(\"DeviceRGBA\");\n        } else {\n          switch (image.numComps) {\n            case 1:\n              colorSpace = Name.get(\"DeviceGray\");\n              break;\n            case 3:\n              colorSpace = Name.get(\"DeviceRGB\");\n              break;\n            case 4:\n              colorSpace = Name.get(\"DeviceCMYK\");\n              break;\n            default:\n              throw new Error(\n                `Images with ${image.numComps} color components not supported.`\n              );\n          }\n        }\n      } else if (this.jpxDecoderOptions?.smaskInData) {\n        // If the jpx image has a color space then it mustn't be used in order\n        // to be able to use the color space that comes from the pdf.\n        colorSpace = Name.get(\"DeviceRGBA\");\n      }\n\n      this.colorSpace = ColorSpaceUtils.parse({\n        cs: colorSpace,\n        xref,\n        resources: isInline ? res : null,\n        pdfFunctionFactory,\n        globalColorSpaceCache,\n        localColorSpaceCache,\n      });","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/image.js#L215-L251","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// For images you author, map component counts to a ColorSpace explicitly:\nfunction defaultColorSpaceForComponents(numComps) {\n  switch (numComps) {\n    case 1: return 'DeviceGray';\n    case 3: return 'DeviceRGB';\n    case 4: return 'DeviceCMYK';\n    default: return null; // must specify ColorSpace explicitly\n  }\n}","typeGuard":"function isInferableComponentCount(n) {\n  return n === 1 || n === 3 || n === 4;\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (/color components not supported/.test(err?.message || '')) {\n    console.warn('Image has unsupported component count; skipping.');\n  } else throw err;\n}","preventionTips":["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."],"tags":["pdf","image","color-space","malformed-pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}