mPDF Manual – Fonts & Languages

lang v5.x

When creating a multilingual document containing Arabic, Indic, CJK, Vietnamese or Thai languages, the text in these languages needs to be identified in order to correctly display them using appropriate fonts.

Marking up your HTML text using the lang attribute is one way to do this. The attribute can be used on any block or in-line tag e.g. <div lang="zh-CN">....</div> or <span lang="ru">...</span>. It is also recognised in <body> or <html> tags.

Important: Support for the attribute $lang is only active when the variable $useLang is set to true (Default).

The language codes supported are determined by config_cp.php :

  • en, ca, cy, da, de, es, eu, fr, ga, fi, is, it, nl, no, pt, sv
  • cs, hr, hu, pl, ro, sk, sl
  • bg, mk, ru, sr, uk
  • et, kl, lt, lv
  • el, tr
  • vi, th
  • CJK: ja, zh, zh-CN, zh-HK, zh-TW, ko
  • RTL: he, ar, fa, ps, ur, sd
  • INDIC: as, bn, gu, hi, kn, ks, ml, ne, or, pa, sd-IN, ta, te

See ISO 639-1 language codes.

Codes such as 'en-US' are supported, and interpreted as 'en'

When a language is set, the following happens (determined by function GetCodepage()):

  • available fonts are restricted to those which contain the necessary glyphs to display this language
  • justification type (jSpacing mPDF < 5.1) is set when a block tag has the property text-align: justify; for span/inline elements the justification is disabled for the enclosing block element.

See Also

  • useLang - Specify whether to recognise and support the HTML attribute lang
  • SetAutoFont() - Use AutoFont to auto-detect text language in HTML input
  • autoFontGroupSize - Specify the text chunk size to group when autodetecting text language
Fork me on GitHub