mozilla/pdf.js · error · FormatError

Invalid TrueType Collection majorVersion: ${majorVersion}.

Error message

Invalid TrueType Collection majorVersion: ${majorVersion}.

What it means

Thrown by readTrueTypeCollectionHeader() when the TTC (TrueType Collection) header's majorVersion field is neither 1 nor 2. The OpenType spec defines only TTC version 1.0 and 2.0 (which adds DSIG digital signature fields); any other major version is treated as invalid.

Source

Thrown at src/core/fonts.js:1539

      }

      const header = {
        ttcTag,
        majorVersion,
        minorVersion,
        numFonts,
        offsetTable,
      };
      switch (majorVersion) {
        case 1:
          return header;
        case 2:
          header.dsigTag = ttc.getInt32() >>> 0;
          header.dsigLength = ttc.getInt32() >>> 0;
          header.dsigOffset = ttc.getInt32() >>> 0;
          return header;
      }
      throw new FormatError(
        `Invalid TrueType Collection majorVersion: ${majorVersion}.`
      );
    }

    function readTrueTypeCollectionData(ttc, fontName) {
      const { numFonts, offsetTable } = readTrueTypeCollectionHeader(ttc);
      const fontNameParts = fontName.split("+");
      let fallbackData;

      for (let i = 0; i < numFonts; i++) {
        ttc.pos = (ttc.start || 0) + offsetTable[i];
        const potentialHeader = readOpenTypeHeader(ttc);
        const potentialTables = readTables(ttc, potentialHeader.numTables);

        if (!potentialTables.name) {
          throw new FormatError(
            'TrueType Collection font must contain a "name" table.'
          );

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Re-save the font collection with fonttools or FontForge to produce a valid TTC version 1 or 2.
  2. Verify the file is genuinely a TTC with ots-sanitize or fc-query before embedding.
  3. If the font is not a collection, fix the PDF to reference the font file directly rather than wrapping it in a TTC container.
  4. Extract individual fonts from the TTC with fonttools (ttCollection) and embed the needed font standalone.

Example fix

# verify and rebuild TTC with fonttools
from fontTools import ttLib
ttc = ttLib.TTCollection('broken.ttc')  # raises on truly corrupt
ttc.save('fixed.ttc')  # writes valid version-1 TTC

# or extract a single font to avoid TTC entirely
font = ttLib.TTFont('broken.ttc', fontNumber=0)
font.save('single.ttf')
Defensive patterns

Strategy: validation

Validate before calling

// Server-side: verify TTC header version
function isValidTtc(buffer) {
  const view = new DataView(buffer);
  const tag = String.fromCharCode(view.getUint8(0), view.getUint8(1), view.getUint8(2), view.getUint8(3));
  if (tag !== 'ttcf') return { ok: true, isTtc: false };  // not a TTC — fine
  const majorVersion = view.getUint16(4);
  return { ok: majorVersion === 1 || majorVersion === 2, isTtc: true, majorVersion };
}

Try / catch

try {
  await page.render(renderParams).promise;
} catch (err) {
  if (err.message?.includes('Invalid TrueType Collection majorVersion')) {
    console.error('TTC font has unsupported version; replace the embedded font collection.');
  } else { throw err; }
}

Prevention

When it happens

Trigger: readTrueTypeCollectionHeader(ttc) reads ttc.getUint16() for majorVersion, and the switch falls through without matching case 1 or case 2. Called when isTrueTypeCollectionFile(font) returns true (ttcTag is 'ttcf') but the version bytes are corrupt.

Common situations: A file with a 'ttcf' tag but corrupt or zeroed version bytes. A font file that is not actually a TTC but happens to start with 'ttcf'. A TTC file truncated so the header is incomplete. Future TTC versions (3.0+) not yet supported by pdf.js.

Related errors


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