{"record":{"id":"1872700c2a0d625a","repo":"PHPOffice/PhpSpreadsheet","slug":"truetype-font-file-not-found","errorCode":null,"errorMessage":"TrueType Font file not found","messagePattern":"TrueType Font file not found","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Shared/Font.php","lineNumber":597,"sourceCode":"                // Neither bold nor italic:\n                //   Impact\n                //   Lucida Console\n                //   Lucida Sans Unicode\n                //   Microsoft Sans Serif\n                //   Symbol\n                if ($index === 'xb') {\n                    $alternateName .= ' Bold';\n                } elseif ($index === 'xi') {\n                    $alternateName .= ' Italic';\n                } elseif ($fontArray[$name]['xb'] === $fontArray[$name]['xbi']) {\n                    $alternateName .= ' Bold';\n                } else {\n                    $alternateName .= ' Bold Italic';\n                }\n            }\n            $fontFile = self::$trueTypeFontPath . $separator . $alternateName . '.ttf';\n            if (!file_exists($fontFile)) {\n                throw new PhpSpreadsheetException('TrueType Font file not found');\n            }\n        }\n\n        return $fontFile;\n    }\n\n    public const CHARSET_FROM_FONT_NAME = [\n        'EucrosiaUPC' => self::CHARSET_ANSI_THAI,\n        'Wingdings' => self::CHARSET_SYMBOL,\n        'Wingdings 2' => self::CHARSET_SYMBOL,\n        'Wingdings 3' => self::CHARSET_SYMBOL,\n    ];\n\n    /**\n     * Returns the associated charset for the font name.\n     *\n     * @param string $fontName Font name\n     *","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Shared/Font.php#L579-L615","documentation":"Thrown by Font::getTrueTypeFontFileFromFont() after it failed to locate the .ttf file for the requested style. When the primary mapped filename is not on disk, the code builds an 'alternate name' (font name plus ' Bold'/' Italic'/' Bold Italic') inside the configured font directory; if that file also does not exist, this exception is raised.","triggerScenarios":"Font::setTrueTypeFontPath($dir) points to a directory that lacks the specific style variant, e.g. cells formatted bold with Calibri while only calibri.ttf (no calibrib.ttf) is in the directory; or an extra-font array whose filenames do not match what is actually on disk; or the extra array omitted the 'xb'/'xi'/'xbi' keys so the alternate-name fallback runs and its file is missing.","commonSituations":"Copying only the regular weight of a font into the container; case-sensitivity surprises on Linux when the file is Calibri.TTF but the code looks for calibri.ttf; an extra font array written with placeholder filenames never replaced; fonts directory mounted read-only and incompletely populated.","solutions":["List Font::getTrueTypeFontPath() and confirm every variant used by the sheet (regular, bold, italic, bold-italic) exists with the exact filename (case-sensitive on Linux).","When registering custom fonts via Font::setExtraFontArray(), provide all four keys ('x','xb','xi','xbi') with the real filenames from the directory.","Rename the files on disk to match the alternate-name convention the fallback expects ('<Font Name> Bold.ttf', '<Font Name> Italic.ttf', '<Font Name> Bold Italic.ttf').","Alternatively drop to Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_APPROX) so no font file is opened at all."],"exampleFix":"// before\n// /var/www/fonts contains only calibri.ttf, sheet uses bold font\nFont::setTrueTypeFontPath('/var/www/fonts');\nFont::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT);\n// TrueType Font file not found\n\n// after\n// copy all variants into the directory:\n// calibri.ttf calibrib.ttf calibrii.ttf calibriz.ttf\nFont::setTrueTypeFontPath('/var/www/fonts');\nFont::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT);","handlingStrategy":"validation","validationCode":"$dir = \\PhpOffice\\PhpSpreadsheet\\Shared\\Font::getTrueTypeFontPath();\nforeach (['', ' Bold', ' Italic', ' Bold Italic'] as $suffix) {\n    $file = \"$dir/{$fontName}{$suffix}.ttf\";\n    if (!is_file($file)) { /* ensure the file is deployed before enabling exact autosize */ }\n}","typeGuard":null,"tryCatchPattern":"try { $writer->save($path); }\ncatch (\\PhpOffice\\PhpSpreadsheet\\Exception $e) {\n    if (str_contains($e->getMessage(), 'TrueType Font file not found')) {\n        \\PhpOffice\\PhpSpreadsheet\\Shared\\Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_APPROX);\n        $writer->save($path);\n    } else { throw $e; }\n}","preventionTips":["Ship the full style family (regular/bold/italic/bold-italic) of every font you style cells with.","Filenames are case-sensitive on Linux — verify with a deploy-time check that every mapped .ttf exists exactly as named.","Provide all four keys ('x','xb','xi','xbi') when registering extra fonts so the alternate-name fallback is never needed."],"tags":["fonts","file-not-found","column-autosize","phpspreadsheet"],"backgroundTag":"font-file-missing","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}