Guides › mPDF › Fonts and languages

Fonts and languages

Written for mPDF 8.2 on PHP 8.1+. Updated 2 November 2026.

Every character in a PDF has to come from a font that contains it. Most “squares instead of letters” problems in mPDF come down to that one fact.

Built-in fonts

mPDF ships with a large set of free fonts. DejaVu Sans (dejavusans), DejaVu Serif and DejaVu Sans Mono cover Latin, Greek and Cyrillic, and there are dedicated fonts for many other scripts. Use them by their lower-case key in CSS:

body { font-family: dejavusans; }

With 'mode' => 'c' mPDF uses only the PDF core fonts (Helvetica, Times, Courier). Those files are tiny, but anything outside Western European characters won’t display.

Adding your own font

CSS @font-face is not supported. Register the files in the configuration instead:

$defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults();
$defaultFonts = (new \Mpdf\Config\FontVariables())->getDefaults();

$mpdf = new \Mpdf\Mpdf([
    'fontDir' => array_merge($defaultConfig['fontDir'], [__DIR__ . '/fonts']),
    'fontdata' => $defaultFonts['fontdata'] + [
        'brandsans' => [
            'R' => 'BrandSans-Regular.ttf',
            'B' => 'BrandSans-Bold.ttf',
            'I' => 'BrandSans-Italic.ttf',
        ],
    ],
    'default_font' => 'brandsans',
]);

Then use font-family: brandsans;. The key must be lower case with no spaces. mPDF embeds only the characters you use (subsetting), so large fonts don’t bloat the file. Make sure the font’s licence allows embedding.

Mixed languages

For text that mixes scripts, such as user names from anywhere, let mPDF pick fonts:

$mpdf = new \Mpdf\Mpdf([
    'autoScriptToLang' => true,  // detect the script of each run of text
    'autoLangToFont' => true,    // choose a font that covers that language
]);

You can also mark content explicitly with the lang attribute: <p lang="ja">…</p>.

Right-to-left text

Arabic, Hebrew, Persian and Urdu need both the right font and right-to-left layout:

<div dir="rtl" lang="ar">المكتبة مفتوحة من الاثنين إلى السبت</div>

For a whole document that reads right to left, call $mpdf->SetDirectionality('rtl');. Arabic letters are joined and shaped automatically, and numbers and Latin words inside RTL text are ordered correctly.

Chinese, Japanese and Korean

CJK fonts are large. With autoLangToFont on, mPDF switches to its bundled CJK fonts when it meets those characters. A document that is mostly CJK should set a suitable default_font, which keeps the font switching (and file size) down.

Checklist when letters show as boxes

  1. Does the font in use actually contain those characters? Try dejavusans to find out.
  2. Is mode set to c? Switch to utf-8.
  3. Is the text really UTF-8? Check what your database connection and source files return.

The multilingual example mixes six languages, including Arabic and Japanese.