How do I add additional Fonts to CiviCRM, especially where wkhtmltopdf and dompdf aren't used?

This is the case when name Badges for an event are printed, and the font isn't capable of of special chars in names.

There is some information already here - but I had to puzzle and try and error a lot, so I decided to write question and answer a bit more conclusively here.


Fonts for TCPDF are generated, and are located in civicrm/vendor/tecnickcom/tcpdf/fonts/ in a format like this:

-rw-r--r-- 1 www-data www-data 1,9K Aug  9 14:44 robotoi.ctg.z
-rw-r--r-- 1 www-data www-data 8,6K Aug  9 14:44 robotoi.php
-rw-r--r-- 1 www-data www-data  78K Aug  9 14:44 robotoi.z

To generate the fonts, a static method from the library addTTFfont is called, and saved to the previously mentioned folder.

$roboto_italic             = TCPDF_FONTS::addTTFfont('/var/www/boell_testing/public/sites/default/files/civicrm/persist/fonts/roboto/roboto/Roboto-Italic.ttf', 'TrueTypeUnicode', '', 32);

After this call, the fonts should be available. The civicrm has to be told that there are additional fonts, which is done via a global settings array:

global $civicrm_setting;
$civicrm_setting['CiviCRM Preferences']['additional_fonts'][$roboto_italic] = "Roboto Italique";

In civicrm/CRM/Utils/PDF/Label.php --> public function getFontNames() the fonts are added to the menu and are available in the drop down menus for, in this case name Badges. But every other PDF generator using TCPDF should have the fonts as well.

  • Depending on your setup, this can cause problems in different stages of bootstrapping CiviCRM, since for example for tests or API Commands TCPDF wont be loaded, thus it fails. I would suggest to generate the fonts like this post, and then statically add them afterwards $civicrm_setting['CiviCRM Preferences']['additional_fonts']['robotoi'] = "Roboto Italique";
    – Phil_B
    Oct 23 '18 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.