mPDF Manual – What Else Can I Do


(mPDF >= 2.5)

Hyphenation was changed in mPDF 5.7 to support the CSS property hyphens (cf.)

The CSS property $hyphens is supported on block elements (e.g. <div>), inline elements (e.g. <span>) and <td/th>.

hyphens: none manual auto

Default = manual

The default can be changed by altering $defaultCSS in config.php

hyphens: manual


Words are not broken at line breaks, even if characters inside the word suggest line break points.


Words are only broken at line breaks where there are characters inside the word that suggest line break opportunities. Characters can be explicit or conditional.


Words can be broken at appropriate hyphenation points, as determined by characters inside the word, resources.

SHY inside the word take priority over hyphenation points determined by other resources.

Soft hyphens

The soft-hyphen character (U+00AD or &shy;) and the <wbr> tag (from mPDF 5.7) are supported in WriteHTML().

Automatic hyphenation

Automatic hyphenation is set using CSS:

hyphens: auto;

Automatic hyphenation is based on the commonly used TeX algorithm and requires pattern files for each language. The following languages are supplied with mPDF 2.5:

**Language** $SHYlang
English en (DEFAULT)
German de
Spanish es
Finnish fi
French fr
Italian it
Dutch nl
Portuguese pl
Russian ru
Swedish sv

A pattern file for each language is found in the folder /patterns/ and the variable $SHYlanguages needs to be updated in config.php if any additions are made.

Pattern checking can be fine-tuned by 4 variables if required:

  Default value  
$SHYleftmin 2 Minimum number of characters allowed to the left of a hyphen.
$SHYrightmin 2 Minimum number of characters allowed to the right of a hyphen.
$SHYcharmin 2 Minimum number of characters of words to be checked.
$SHYcharmax 10 Maximum number of characters in a pattern used for pattern checking (10 usually is more than enough). this is NOT the maximum length of words to be checked.

Example #1


$mpdf = new mPDF();

$mpdf->SHYlang = 'fr';

$mpdf->SHYleftmin = 3;

La grande texte....



Hyphenation Dictionary

If automatic hyphenation does not recognise a particular word, you can add words to a dictionary file with your own hyphenation. Edit the file “pathtoyourmpdf/patterns/dictionary.txt” and add a new line for each word, marking the possible hyphenations with a forward slash. You can mark more than one place for each word e.g. “dis/es/tab/lish/men/tar/i/an/ism”

See Also

  • SHYlang - Specify the language to use for automatic hyphenation