mozilla/pdf.js · error · FormatError
No domain
Error message
No domain
What it means
Thrown by PDFFunction.constructStiched (FunctionType 3) when the /Domain array is missing or non-numeric. A stitching function combines several sub-functions over a single input dimension, so Domain is mandatory to define the input range.
Source
Thrown at src/core/function.js:294
for (let i = 0, ii = c0.length; i < ii; ++i) {
diff.push(c1[i] - c0[i]);
}
const length = diff.length;
return function constructInterpolatedFn(src, srcOffset, dest, destOffset) {
const x = n === 1 ? src[srcOffset] : src[srcOffset] ** n;
for (let j = 0; j < length; ++j) {
dest[destOffset + j] = c0[j] + x * diff[j];
}
};
}
static constructStiched(factory, dict) {
const domain = toNumberArray(dict.getArray("Domain"));
if (!domain) {
throw new FormatError("No domain");
}
const inputSize = domain.length / 2;
if (inputSize !== 1) {
throw new FormatError("Bad domain for stiched function");
}
const { xref } = factory;
const fns = [];
for (const fn of dict.get("Functions")) {
fns.push(this.parse(factory, xref.fetchIfRef(fn)));
}
const bounds = toNumberArray(dict.getArray("Bounds"));
const encode = toNumberArray(dict.getArray("Encode"));
const tmpBuf = new Float32Array(1);
return function constructStichedFn(src, srcOffset, dest, destOffset) {View on GitHub (pinned to 5903d58d58)
Solutions
- Verify the PDF renders in Acrobat; if yes, file a pdf.js issue with the file.
- When authoring stitching functions, always provide /Domain as exactly one input interval, e.g. [0 1].
- Wrap render in try/catch and degrade for the affected page.
- Use qpdf/mutool to repair the file's xref/object stream before re-rendering.
Defensive patterns
Strategy: try-catch
Validate before calling
function stitchingHasDomain(dict) {
const d = dict.getArray?.('Domain');
return Array.isArray(d) && d.every(Number.isFinite);
} Type guard
function isValidStitchingDomain(arr) {
return Array.isArray(arr) && arr.length === 2 &&
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 domain') {
console.warn('Stitching function missing domain; skipping shading.');
} else throw err;
} Prevention
- Always set /Domain on Type 3 stitching functions during PDF generation.
- Validate PDFs with qpdf/mutool before distribution.
- Wrap rendering per-page so a single bad gradient is non-fatal.
When it happens
Trigger: A FunctionType 3 dictionary lacking /Domain (or whose Domain is not a number array) is encountered while rendering a shading pattern, gradient, or Indexed color space lookup that uses stitching.
Common situations: Malformed PDFs from buggy generators, or PDFs whose stitching function was truncated during a copy/merge operation. Commonly surfaces in multi-stop gradient fills.
Related errors
- Unknown function type: ${typeNum}
- No domain or range
- Bad domain for stiched function
- No domain.
- No range.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/0ca46fe5d10776c0.
Report an issue: GitHub.