mozilla/pdf.js · error · FormatError
WhitePoint missing - required for color space CalRGB
Error message
WhitePoint missing - required for color space CalRGB
What it means
Thrown by the CalRGBCS constructor when the /WhitePoint array is missing or falsy for a /CalRGB color space. As with CalGray, WhitePoint is mandatory per spec and pdf.js will not guess a default for it.
Source
Thrown at src/core/colorspace.js:942
3.2404542, -1.5371385, -0.4985314,
-0.9692660, 1.8760108, 0.0415560,
0.0556434, -0.2040259, 1.0572252]);
static #FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
static #tempNormalizeMatrix = new Float32Array(3);
static #tempConvertMatrix1 = new Float32Array(3);
static #tempConvertMatrix2 = new Float32Array(3);
static #DECODE_L_CONSTANT = ((8 + 16) / 116) ** 3 / 8.0;
constructor(whitePoint, blackPoint, gamma, matrix) {
super("CalRGB", 3);
if (!whitePoint) {
throw new FormatError(
"WhitePoint missing - required for color space CalRGB"
);
}
// Translate arguments to spec variables.
const [XW, YW, ZW] = (this.whitePoint = whitePoint);
const [XB, YB, ZB] = (this.blackPoint = blackPoint || new Float32Array(3));
[this.GR, this.GG, this.GB] = gamma || new Float32Array([1, 1, 1]);
[
this.MXA,
this.MYA,
this.MZA,
this.MXB,
this.MYB,
this.MZB,
this.MXC,
this.MYC,
this.MZC,View on GitHub (pinned to 5903d58d58)
Solutions
- Repair the PDF to include a valid /WhitePoint array (Y normalized to 1).
- Update pdf.js.
Defensive patterns
Strategy: try-catch
Type guard
function hasWhitePoint(csDict) {
const wp = csDict.get('WhitePoint');
return Array.isArray(wp) && wp.length === 3;
} Try / catch
try {
cs = ColorSpace.parse(res, xref, cs, pdfFunctionFactory);
} catch (e) {
if (e instanceof FormatError && /WhitePoint missing.*CalRGB/.test(e.message)) {
console.warn('CalRGB missing WhitePoint, falling back', e);
cs = null;
} else throw e;
} Prevention
- When generating /CalRGB color spaces, always include /WhitePoint.
- Validate untrusted PDFs before rendering.
- Keep pdf.js updated.
- Fall back to DeviceRGB when CalRGB construction fails.
When it happens
Trigger: Constructing CalRGBCS with whitePoint = null/undefined/[], or parsing a PDF /CalRGB dictionary lacking /WhitePoint.
Common situations: Corrupt PDF with an incomplete CalRGB dictionary; a faulty PDF writer that omitted the calibration white point.
Related errors
- WhitePoint missing - required for color space CalGray
- WhitePoint missing - required for color space Lab
- IndexedCS - unrecognized lookup table: ${lookup}
- Invalid WhitePoint components for ${this.name}, no fallback
- Invalid WhitePoint components, no fallback available
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/8624262d0a23d04e.
Report an issue: GitHub.