DomPDF : load custom local fonts in you own folder
Par Mathieu le vendredi 12 février 2016, 23:28 - Hacks - Lien permanent
I needed custom fonts for domPDF, but I didn’t want to use the “remote” capabilities of domPDF, and I didn’t wanted to spoil my “contrib” folder with my own fonts. Dependencies should remain clean.
My domPDF version was 0.6.3.
To use your own “fonts” folder in order to autoload you own fonts, do :
Creates a directory for your fonts and font cache :
mkdir myfonts
- Copy your .ttf files in this folder.
- Creates a file named dompdf_font_family_cache.php in the myfonts folder, and reference your files. As a sample, you can use the file dompdf/lib/fonts/dompdf_font_family_cache.dist.php
- In your configuration (dompdf_config.custom.inc.php), change the DOMPDF_FONT_DIR and DOMPDF_FONT_CACHE to point on your folder myfonts (relative use realpath on relative paths).
- Use your fonts like native fonts in font-family declarations.
I hope it will be useful to you.