mozilla/pdf.js · error · FormatError
No range.
Error message
No range.
What it means
Thrown by PDFFunction.constructPostScript (FunctionType 4) when /Range is missing or non-numeric, after Domain has already been validated. Range defines the output dimensionality and clipping for the PostScript calculator and is required before the program can be compiled.
Source
Thrown at src/core/function.js:352
dmin === dmax
? rmin
: rmin + ((v - dmin) * (rmax - rmin)) / (dmax - dmin);
// call the appropriate function
fns[i](tmpBuf, 0, dest, destOffset);
};
}
static constructPostScript(factory, fn, dict) {
const domain = toNumberArray(dict.getArray("Domain"));
const range = toNumberArray(dict.getArray("Range"));
if (!domain) {
throw new FormatError("No domain.");
}
if (!range) {
throw new FormatError("No range.");
}
const psCode = fn.getString();
try {
if (factory.useWasm) {
const wasmFn = buildPostScriptWasmFunction(psCode, domain, range);
if (wasmFn) {
return wasmFn; // (src, srcOffset, dest, destOffset) → void
}
}
} catch {}
warn("Failed to compile PostScript function to wasm, falling back to JS");
return buildPostScriptJsFunction(psCode, domain, range);
}
}View on GitHub (pinned to 5903d58d58)
Solutions
- Emit /Range as a flat numeric array of even length for every Type 4 function when generating PDFs.
- Validate the PDF in Acrobat and report discrepancies to pdf.js.
- Catch FormatError around the render pipeline and skip the affected page.
- Use qpdf --check or a PDF/A validator to flag the missing required entry.
Defensive patterns
Strategy: try-catch
Validate before calling
function postScriptHasRange(dict) {
const r = dict.getArray?.('Range');
return Array.isArray(r) && r.every(Number.isFinite) && r.length % 2 === 0;
} Type guard
function isNumericIntervalArray(arr) {
return Array.isArray(arr) && arr.length % 2 === 0 &&
arr.every(x => typeof x === 'number' && Number.isFinite(x));
} Try / catch
try { await page.render({ canvasContext }).promise; }
catch (err) {
if (err?.name === 'FormatError' && err.message === 'No range.') {
console.warn('PostScript function missing range; skipping.');
} else throw err;
} Prevention
- Always emit /Range on Type 4 functions when authoring PDFs.
- Run qpdf --check to detect missing required entries.
- Isolate rendering per-page to contain failures.
When it happens
Trigger: A FunctionType 4 stream with a valid Domain but missing/non-numeric Range. Encountered during compilation of a PostScript calculator function referenced by a shading or Indexed color space.
Common situations: Incomplete Type 4 functions from buggy PDF generators; truncated object streams after a merge; ICC profile-driven gradients where Range was omitted.
Related errors
- No domain.
- Unknown function type: ${typeNum}
- No domain or range
- No domain
- Bad domain for stiched function
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/da008c1fdedab512.
Report an issue: GitHub.