mozilla/pdf.js · error · Error
Built-in CMap parameters are not provided.
Error message
Built-in CMap parameters are not provided.
What it means
Thrown by createBuiltInCMap when the fetchBuiltInCMap argument is falsy. The library needs a callback to load the binary .bcmap files for any non-Identity built-in CMap; without it, resolving a Name-encoded CMap is impossible. Usually the evaluator supplies this callback, but only when cMapUrl is configured.
Source
Thrown at src/core/cmap.js:682
if (!cMap.contains(key)) {
cMap.mapOne(key, value);
}
});
return cMap;
}
async function createBuiltInCMap(name, fetchBuiltInCMap) {
if (name === "Identity-H") {
return new IdentityCMap(false, 2);
} else if (name === "Identity-V") {
return new IdentityCMap(true, 2);
}
if (!BUILT_IN_CMAPS.includes(name)) {
throw new Error("Unknown CMap name: " + name);
}
if (!fetchBuiltInCMap) {
throw new Error("Built-in CMap parameters are not provided.");
}
const { cMapData, isCompressed } = await fetchBuiltInCMap(name);
const cMap = new CMap(true);
if (isCompressed) {
return new BinaryCMapReader().process(cMapData, cMap, useCMap =>
extendCMap(cMap, fetchBuiltInCMap, useCMap)
);
}
const lexer = new Lexer(new Stream(cMapData));
return parseCMap(cMap, lexer, fetchBuiltInCMap, null);
}
class CMapFactory {
static async create({ encoding, fetchBuiltInCMap, useCMap }) {
if (encoding instanceof Name) {
return createBuiltInCMap(encoding.name, fetchBuiltInCMap);View on GitHub (pinned to 5903d58d58)
Solutions
- Pass cMapUrl and cMapPacked: true to getDocument, pointing at the bundled cmaps/ directory from pdfjs-dist.
- If using a custom worker setup, supply a fetchBuiltInCMap(name) callback returning { cMapData: ArrayBuffer, isCompressed: boolean }.
- For node, install pdfjs-dist and point cMapUrl at its cmaps/ folder (e.g. node_modules/pdfjs-dist/cmaps/).
Example fix
// before
getDocument({ url }); // no CMap config -> CJK fonts fail
// after
getDocument({
url,
cMapUrl: '/node_modules/pdfjs-dist/cmaps/',
cMapPacked: true,
}); Defensive patterns
Strategy: validation
Validate before calling
// Ensure a fetcher is configured before loading a CMap-dependent PDF
function buildFetchBuiltInCMap(cMapUrl, cMapPacked) {
if (!cMapUrl) return null;
return async (name) => {
const suffix = cMapPacked ? '.bcmap' : '';
const cMapData = await fetch(`${cMapUrl}${name}${suffix}`).then(r => r.arrayBuffer());
return { cMapData, isCompressed: cMapPacked };
};
} Type guard
function hasCMapFetcher(opts) {
return typeof opts.fetchBuiltInCMap === 'function'
|| (typeof opts.cMapUrl === 'string' && opts.cMapUrl.length > 0);
} Prevention
- Always pass cMapUrl (and cMapPacked: true) to getDocument for documents that may use CID/CJK fonts.
- When calling CMapFactory.create directly, pass a non-null fetchBuiltInCMap callback.
- For node.js, point cMapUrl at node_modules/pdfjs-dist/cmaps/.
- Add a smoke-test that loads a CJK sample PDF in CI to catch missing CMap config.
When it happens
Trigger: Calling CMapFactory.create({ encoding: Name, fetchBuiltInCMap: null }) directly, or running the worker without cMapUrl configured so PartialEvaluator never builds a fetcher and passes undefined through.
Common situations: Embedding pdf.js without setting cMapUrl/cMapPacked in getDocument; node.js usage that constructs the evaluator manually; a stripped-down build that omits the standard CMap loading path.
Related errors
- Unknown CMap name: ${name}
- Max size of CID is 65,535
- mapCidRange - ignoring data above MAX_MAP_RANGE.
- mapBfRange - ignoring data above MAX_MAP_RANGE.
- mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/1a4802074ef69c58.
Report an issue: GitHub.