mozilla/pdf.js · error · FormatError
Required "loca" table is not found
Error message
Required "loca" table is not found
What it means
Thrown during Font.convertTrueType (the TrueType font processing branch) when a TrueType font (one without a CFF table) is missing the required 'loca' table. The 'loca' table stores offsets to glyph data in the 'glyf' table and is mandatory for TrueType outlines. Unlike the missing 'glyf' case (which warns and recovers), a missing 'loca' table is unrecoverable.
Source
Thrown at src/core/fonts.js:2785
!tables.post
) {
// No major tables: throwing everything at `CFFFont`.
return this.convert(
name,
new CFFFont(new Stream(tables["CFF "].data), properties),
properties
);
}
delete tables.glyf;
delete tables.loca;
delete tables.fpgm;
delete tables.prep;
delete tables["cvt "];
this.isOpenType = true;
} else {
if (!tables.loca) {
throw new FormatError('Required "loca" table is not found');
}
if (!tables.glyf) {
warn('Required "glyf" table is not found -- trying to recover.');
// Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
tables.glyf = {
tag: "glyf",
data: new Uint8Array(0),
};
}
this.isOpenType = false;
}
if (!tables.maxp) {
throw new FormatError('Required "maxp" table is not found');
}
let numGlyphsFromCFF;
if (parsedCff) {View on GitHub (pinned to 5903d58d58)
Solutions
- Rebuild the font with fonttools (load + save) to regenerate the loca table from glyph data.
- If the font is actually CFF-based, ensure the 'CFF ' table is present so pdf.js takes the OpenType branch instead.
- Replace the corrupt embedded font with a complete TrueType font.
- Validate the font with ots-sanitize before embedding.
Example fix
# regenerate the loca table
from fontTools import ttLib
font = ttLib.TTFont('broken.ttf') # fontTools rebuilds loca on save
font.save('fixed.ttf')
ots-sanitize fixed.ttf # verify Defensive patterns
Strategy: validation
Validate before calling
// Server-side: verify TrueType font has a loca table
// from fontTools import ttLib
// font = ttLib.TTFont('font.ttf')
// if 'glyf' in font and 'loca' not in font:
// print('TrueType font missing loca table')
function hasRequiredTables(fontPath) {
// Use fonttools/ots-sanize server-side; JS lacks a robust SFNT validator.
// Return false if loca is missing for a TrueType (glyf-based) font.
} Try / catch
try {
await page.render(renderParams).promise;
} catch (err) {
if (err.message?.includes('Required "loca" table is not found')) {
console.error('TrueType font missing loca table; replace embedded font.');
} else { throw err; }
} Prevention
- Ensure all TrueType fonts include mandatory tables: head, hhea, maxp, loca, glyf, cmap, name, post.
- Rebuild fonts with fonttools (load + save) to regenerate loca.
- Run ots-sanitize on fonts before embedding in PDFs.
When it happens
Trigger: In the else branch (isTrueType === true, no CFF table), tables.loca is falsy. The check at line 2784 throws. Note: if the font has a CFF table and also lacks head/hhea/maxp/post, it diverts to this.convert() at line 2770 before reaching this check.
Common situations: A corrupt or stripped TrueType font where the 'loca' table was removed. A font file that was truncated, cutting off the loca table. A non-standard font produced by buggy subsetting tools that failed to include loca. A font incorrectly identified as TrueType when it should be processed as CFF.
Related errors
- Could not fix indexToLocFormat: ${indexToLocFormat}
- Required "maxp" table is not found
- Required "head" table is not found
- Required "hhea" table is not found
- unsupported cmap: ${format}
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/8902e7b48b53373d.
Report an issue: GitHub.