(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.
inline elements (e.g.
The default can be changed by altering
none- Words are not broken at line breaks, even if characters inside the word suggest line break points.
manual- 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.
auto- Words can be broken at appropriate hyphenation points, as determined by characters inside the word, resources. SHY (i.e. soft-hyphen) inside the word take priority over hyphenation points determined by other resources.
The soft-hyphen character (U+00AD or
­) and the
<wbr> tag (from mPDF 5.7) are supported in
Automatic hyphenation is set using CSS:
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:
A pattern file for each language is found in the directory
[mpdf root]/data/patterns/ and the
$SHYlanguages needs to be updated if any additions are made.
The $SHYlang variable specifies which language to use for the automatic hyphenation from
the $SHYlanguages array.
Pattern checking can be fine-tuned by four variables if required:
|mPDF variable||Default value||Description|
||Minimum number of characters allowed to the left of a hyphen.|
||Minimum number of characters allowed to the right of a hyphen.|
||Minimum number of characters of words to be checked.|
||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.|
<?php $mpdf = new \Mpdf\Mpdf(); $mpdf->SHYlang = 'fr'; $mpdf->SHYleftmin = 3; $mpdf->WriteHTML('Le long texte....'); $mpdf->Output();
If automatic hyphenation does not recognise a particular word, you can add words to a dictionary file with your own
hyphenation. Edit the file
[path to mpdf]/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.
- SHYlang - Specify the language to use for automatic hyphenation