mozilla/pdf.js · error · FormatError

Required "maxp" table is not found

Error message

Required "maxp" table is not found

What it means

Thrown when the font's table directory lacks a 'maxp' (Maximum Profile) table. The maxp table is mandatory in both TrueType and OpenType fonts — it stores the number of glyphs, memory requirements, and other limits. Without it, the font processor cannot determine numGlyphs or validate table sizes.

Source

Thrown at src/core/fonts.js:2799

      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) {
      try {
        parsedCff.duplicateFirstGlyph();
        tables["CFF "].data = new CFFCompiler(parsedCff).compile();
        numGlyphsFromCFF = parsedCff.charStringCount;
      } catch {
        warn("Failed to compile font " + properties.loadedName);
      }
    }

    font.pos = (font.start || 0) + tables.maxp.offset;
    let version = font.getInt32();
    const numGlyphs = numGlyphsFromCFF ?? font.getUint16();
    if (version === 0x00005000 && tables.maxp.length !== 6) {
      tables.maxp.data = tables.maxp.data.subarray(0, 6);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Replace the corrupt font with a complete, valid font file.
  2. Rebuild the font with fonttools to regenerate all mandatory tables including maxp.
  3. Validate the PDF's embedded font stream is not truncated — check its stream length against the actual data.
  4. If the font is embedded in the PDF, extract it and verify with ots-sanitize.

Example fix

# extract and validate embedded font from PDF
# using fonttools + mutool
mutool extract broken.pdf   # extract embedded fonts
from fontTools import ttLib
font = ttLib.TTFont('extracted.ttf')  # raises on missing maxp
# replace with a valid font and re-embed
Defensive patterns

Strategy: validation

Validate before calling

// Server-side: verify font has maxp table
// from fontTools import ttLib
// font = ttLib.TTFont('font.ttf')
// assert 'maxp' in font, 'Font missing maxp table'

Try / catch

try {
  await page.render(renderParams).promise;
} catch (err) {
  if (err.message?.includes('Required "maxp" table is not found')) {
    console.error('Font missing maxp table; replace with valid font.');
  } else { throw err; }
}

Prevention

When it happens

Trigger: After the TrueType/CFF branching logic, the check if (!tables.maxp) at line 2798 throws. This applies to both TrueType and OpenType/CFF fonts that reach this point (CFF fonts that have complete head/hhea/maxp/post continue here rather than diverting to this.convert()).

Common situations: A severely truncated or corrupt font file missing core tables. A font file that is not actually a valid OpenType/TrueType file but was embedded as one. Fonts stripped of mandatory tables by aggressive optimization tools. A font offset table pointing to invalid table locations.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/f3602b6a61567b8b. Report an issue: GitHub.