mozilla/pdf.js · error · FormatError
WhitePoint missing - required for color space Lab
Error message
WhitePoint missing - required for color space Lab
What it means
Thrown by the LabCS constructor when the /WhitePoint array is missing or falsy for a /Lab color space. WhitePoint is mandatory for Lab calibration per the PDF spec; pdf.js refuses to default it because Lab color is meaningless without a reference white.
Source
Thrown at src/core/colorspace.js:1207
}
}
getOutputLength(inputLength, alpha01) {
return ((inputLength * (3 + alpha01)) / 3) | 0;
}
}
/**
* LabCS: Based on "PDF Reference, Sixth Ed", p.250
*
* The default color is `new Float32Array([0, 0, 0])`.
*/
class LabCS extends ColorSpace {
constructor(whitePoint, blackPoint, range) {
super("Lab", 3);
if (!whitePoint) {
throw new FormatError(
"WhitePoint missing - required for color space Lab"
);
}
// Translate args to spec variables
[this.XW, this.YW, this.ZW] = whitePoint;
[this.amin, this.amax, this.bmin, this.bmax] = range || [
-100, 100, -100, 100,
];
// These are here just for completeness - the spec doesn't offer any
// formulas that use BlackPoint in Lab
[this.XB, this.YB, this.ZB] = blackPoint || [0, 0, 0];
// Validate vars as per spec
if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
throw new FormatError(
"Invalid WhitePoint components, no fallback available"
);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.*Lab/.test(e.message)) {
console.warn('Lab missing WhitePoint, falling back', e);
cs = null;
} else throw e;
} Prevention
- When generating /Lab color spaces, always include /WhitePoint.
- Validate untrusted PDFs before rendering.
- Keep pdf.js updated.
- Fall back to a default colorspace when Lab construction fails.
When it happens
Trigger: Constructing LabCS with whitePoint = null/undefined/[], or parsing a PDF /Lab dictionary that lacks /WhitePoint.
Common situations: Corrupt PDF with an incomplete Lab dictionary; a faulty PDF generator that omitted the reference white.
Related errors
- WhitePoint missing - required for color space CalGray
- WhitePoint missing - required for color space CalRGB
- Invalid WhitePoint components, no fallback available
- IndexedCS - unrecognized lookup table: ${lookup}
- Invalid WhitePoint components for ${this.name}, no fallback
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/a1b817edcc4b525b.
Report an issue: GitHub.