{"record":{"id":"10b809f03a7f9fc2","repo":"mozilla/pdf.js","slug":"truetype-collection-does-not-contain-fontname","errorCode":null,"errorMessage":"TrueType Collection does not contain \"${fontName}\" font.","messagePattern":"TrueType Collection does not contain \"(.+?)\" font\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/fonts.js","lineNumber":1598,"sourceCode":"                  header: potentialHeader,\n                  tables: potentialTables,\n                };\n              }\n            }\n          }\n        }\n      }\n      if (fallbackData) {\n        warn(\n          `TrueType Collection does not contain \"${fontName}\" font, ` +\n            `falling back to \"${fallbackData.name}\" font instead.`\n        );\n        return {\n          header: fallbackData.header,\n          tables: fallbackData.tables,\n        };\n      }\n      throw new FormatError(\n        `TrueType Collection does not contain \"${fontName}\" font.`\n      );\n    }\n\n    /**\n     * Read the appropriate subtable from the cmap according to 9.6.6.4 from\n     * PDF spec\n     */\n    function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {\n      if (!cmap) {\n        warn(\"No cmap table available.\");\n        return {\n          platformId: -1,\n          encodingId: -1,\n          mappings: [],\n          hasShortCmap: false,\n        };\n      }","sourceCodeStart":1580,"sourceCodeEnd":1616,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/fonts.js#L1580-L1616","documentation":"Thrown by readTrueTypeCollectionData() after scanning all member fonts in a TTC and finding none whose 'name' table entries match the requested fontName — and no partial fallback match was found either. The PDF references a specific font name that the TTC does not contain.","triggerScenarios":"The loop over numFonts completes without returning (no exact nameEntry === fontName match), fallbackData remains null (no fontNameParts partial match), and execution reaches the final throw. The fontName comes from the PDF's font resource name (e.g., 'ABCDEF+Arial').","commonSituations":"The PDF references a font subset prefix (e.g., 'ABCDEF+TimesNewRoman') that doesn't match any name in the TTC. The TTC was replaced or updated but the PDF still references old font names. A mismatch between the PDF's BaseFont name and the actual embedded TTC member names. The fontName uses a different naming convention than the TTC member.","solutions":["Inspect the TTC member font names with fonttools: [TTFont('file.ttc', fontNumber=i)['name'].getDebugName(1) for i in range(count)] and compare with the PDF's BaseFont name.","Ensure the PDF's font resource name matches a name table entry (nameID 1 or 4/6) in the TTC.","Rebuild the PDF ensuring the correct font from the TTC is referenced.","If the font name includes a subset prefix (XXXX+), verify it matches the embedded subset."],"exampleFix":"# find which font names exist in the TTC\nfrom fontTools import ttLib\n\nttc = ttLib.TTCollection('fonts.ttc')\nfor i, font in enumerate(ttc.fonts):\n    name = font['name'].getDebugName(1)  # Family name\n    post = font['name'].getDebugName(6)  # PostScript name\n    print(f'{i}: {name} / {post}')\n# then fix the PDF to reference the matching PostScript name","handlingStrategy":"validation","validationCode":"// Server-side: list all names in the TTC and compare with the PDF's BaseFont\n// from fontTools import ttLib\n// ttc = ttLib.TTCollection('fonts.ttc')\n// available = set()\n// for font in ttc.fonts:\n//     for record in font['name'].names:\n//         available.add(record.toUnicode())\n// if pdfBaseFont not in available:\n//     print(f'{pdfBaseFont} not found in TTC')\n","typeGuard":null,"tryCatchPattern":"try {\n  await page.render(renderParams).promise;\n} catch (err) {\n  if (err.message?.includes('TrueType Collection does not contain')) {\n    console.error('Font name mismatch between PDF and embedded TTC; check BaseFont name.');\n  } else { throw err; }\n}","preventionTips":["Ensure the PDF's BaseFont name exactly matches a name table entry (nameID 6 PostScript name) in the TTC.","Verify subset prefixes (XXXX+) in the PDF match the embedded subset's names.","When updating a TTC, regenerate the PDF so font references stay in sync."],"tags":["font","ttc","font-name","font-matching","truetype-collection","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}