{"record":{"id":"8902e7b48b53373d","repo":"mozilla/pdf.js","slug":"required-loca-table-is-not-found","errorCode":null,"errorMessage":"Required \"loca\" table is not found","messagePattern":"Required \"loca\" table is not found","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/fonts.js","lineNumber":2785,"sourceCode":"        !tables.post\n      ) {\n        // No major tables: throwing everything at `CFFFont`.\n        return this.convert(\n          name,\n          new CFFFont(new Stream(tables[\"CFF \"].data), properties),\n          properties\n        );\n      }\n\n      delete tables.glyf;\n      delete tables.loca;\n      delete tables.fpgm;\n      delete tables.prep;\n      delete tables[\"cvt \"];\n      this.isOpenType = true;\n    } else {\n      if (!tables.loca) {\n        throw new FormatError('Required \"loca\" table is not found');\n      }\n      if (!tables.glyf) {\n        warn('Required \"glyf\" table is not found -- trying to recover.');\n        // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.\n        tables.glyf = {\n          tag: \"glyf\",\n          data: new Uint8Array(0),\n        };\n      }\n      this.isOpenType = false;\n    }\n\n    if (!tables.maxp) {\n      throw new FormatError('Required \"maxp\" table is not found');\n    }\n\n    let numGlyphsFromCFF;\n    if (parsedCff) {","sourceCodeStart":2767,"sourceCodeEnd":2803,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/fonts.js#L2767-L2803","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# regenerate the loca table\nfrom fontTools import ttLib\nfont = ttLib.TTFont('broken.ttf')  # fontTools rebuilds loca on save\nfont.save('fixed.ttf')\nots-sanitize fixed.ttf  # verify","handlingStrategy":"validation","validationCode":"// Server-side: verify TrueType font has a loca table\n// from fontTools import ttLib\n// font = ttLib.TTFont('font.ttf')\n// if 'glyf' in font and 'loca' not in font:\n//     print('TrueType font missing loca table')\nfunction hasRequiredTables(fontPath) {\n  // Use fonttools/ots-sanize server-side; JS lacks a robust SFNT validator.\n  // Return false if loca is missing for a TrueType (glyf-based) font.\n}","typeGuard":null,"tryCatchPattern":"try {\n  await page.render(renderParams).promise;\n} catch (err) {\n  if (err.message?.includes('Required \"loca\" table is not found')) {\n    console.error('TrueType font missing loca table; replace embedded font.');\n  } else { throw err; }\n}","preventionTips":["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."],"tags":["font","loca-table","truetype","required-table","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}