DomPDF is a wonderful library, which helps to generate PDF files on your server.
It also gives a possibility to add custom fonts to setup.
For this purpose there is a special utility load_font.php
just run the following command line on your Linux box and you will get proper fonts for dompdf:
./load_font.php 'Trebuchet MS' /usr/share/fonts/truetype/msttcorefonts/Trebuchet_MS.ttf
The problem I met is the file lib/fonts/dompdf_font_family_cache. This file is used to store fonts’ information for further using in PDF generation.
Actually it is just simple php Array:
array ( 'sans-serif' => array ( 'normal' => '/home/misha/src/dompdf/lib/fonts/Helvetica', 'bold' => '/home/misha/src/dompdf/lib/fonts/Helvetica-Bold', 'italic' => '/home/misha/src/dompdf/lib/fonts/Helvetica-Oblique', 'bold_italic' => '/home/misha/src/dompdf/lib/fonts/Helvetica-BoldOblique', ), 'times' => array ( 'normal' => '/home/misha/src/dompdf/lib/fonts/Times-Roman', 'bold' => '/home/misha/src/dompdf/lib/fonts/Times-Bold', 'italic' => '/home/misha/src/dompdf/lib/fonts/Times-Italic', 'bold_italic' => '/home/misha/src/dompdf/lib/fonts/Times-BoldItalic', ), )
The source of the problem is in full path. If you plan to copy this directory structure to your server, then replace the full path with the definition DOMPDF_FONT_DIR
array ( 'sans-serif' => array ( 'normal' => DOMPDF_FONT_DIR . 'Helvetica', 'bold' => DOMPDF_FONT_DIR . 'Helvetica-Bold', 'italic' => DOMPDF_FONT_DIR . 'Helvetica-Oblique', 'bold_italic' => DOMPDF_FONT_DIR . 'Helvetica-BoldOblique', ), 'times' => array ( 'normal' => DOMPDF_FONT_DIR . 'Times-Roman', 'bold' => DOMPDF_FONT_DIR . 'Times-Bold', 'italic' => DOMPDF_FONT_DIR . 'Times-Italic', 'bold_italic' => DOMPDF_FONT_DIR . 'Times-BoldItalic', ), )
I know you posted this a year ago, but it just helped me today! We couldn’t figure out why our PDF didn’t have the right font, turns out we just needed to update the font cache. Thanks!
This article helped get the formatting for a PDF working properly. On the Mac I found the fonts in the /Library/Fonts folder.
Thanks for posting this information.