Using your own font or CJK characters in PDF output¶
As of CiviCRM 6.0, most unicode characters will output correctly in PDFs. But if you need CJK characters DejaVu does not contain those, so you will need to install another font file such as SimSun using the steps below.
If you are still seeing question marks (?) in place of unicode characters, even for non-CJK characters, check that you don't have a <font>
tag or style
attribute in the html specifically setting a font that doesn't support unicode.
Option A: Using web fonts¶
- In your html template add a
<link>
tag like the following, e.g. for the Noto Sans SC font:<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@100..900">
- Specify the font using CSS in the templates where you use the CJK characters. You can use the Source button in CKEditor to do this and type it directly into the HTML: e.g.
<p style="font-family: Noto Sans SC;">的</p>
Option B: Storing fonts locally¶
- While option A will cache a version of the file after the first download, it may not be available on the internet or may be a commercial font.
- Create a folder in a location that won't get overwritten when you upgrade, e.g. sites/default/fonts for Drupal.
- Copy the .ttf font file you want to use into that folder.
- Run
php -r 'require_once "/path/to/civicrm/vendor/autoload.php"; $f = \FontLib\Font::load("/full/path/to/the/ttf/file"); $f->parse(); $f->saveAdobeFontMetrics("/full/path/to/output/ufm/file");'
- e.g.
php -r 'require_once "/var/www/sites/all/modules/civicrm/vendor/autoload.php"; $f = \FontLib\Font::load("/var/www/sites/default/fonts/simsun.ttf"); $f->parse(); $f->saveAdobeFontMetrics("/var/www/sites/default/fonts/simsun.ufm");'
- e.g.
- Create a file in that folder called
installed-fonts.json
that looks like this:{ "simsun": { "normal": "simsun" } }
- Visit Administer - System Settings - Misc and in the field for DOMPDF Font Folder put the full path to the font folder you created in step 2.
- Specify the font using CSS in the templates where you use the CJK characters. You can use the Source button in CKEditor to do this and type it directly into the HTML: e.g.
<p style="font-family: simsun;">的</p>
- Note any fonts you set up here are in addition to the ones distributed with dompdf/CiviCRM. You do not need to copy those core fonts over or add entries in this json file to use them.