- Issue created by @el35
- 🇮🇳India Akhil Babu Chengannur
Faced similer issue with Japanese text while exporting views as pdf (Entity form views). The following worked for me.
Find a font as per the required language from fonts.google.com. Eg: Noto sans JP.
Download .ttf file for any of the font variations (Eg: Regular) and place it in theme-name/fonts/noto-sans-jp folder.
Create noto-sans-jp.css in the same folder (theme-name/fonts/noto-sans-jp) and add the following styles@font-face { font-family: 'Noto Sans JP'; src: url("NotoSansJP-Regular.ttf") format("truetype"); } # NotoSansJP-Regular.ttf is the font file downloaded to the folder. body { font-family: 'Noto Sans JP', sans-serif !important; }
Include the following code on theme-name.libraries.yml
entity-print-ja: version: 1.x css: theme: fonts/noto-sans-jp/noto-sans-jp.css: {}
Then add this library as a dependency to entity print when current langiage is japanese.
/** * Implements hook_library_info_alter(). */ function my_module_library_info_alter(&$libraries, $extension) { if ($extension == 'entity_print') { $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId(); if ($current_language == 'ja') { $libraries['default']['dependencies'][] = 'theme-name/entity-print-ja'; } } } }
Not sure if this is the proper way but it worked for me.
Note: Some fonts may not have .ttf versions. For example Noto sans KR font only has .otf version in fonts.google.com. There are some online tools available to convert font files to .ttf format, but when I used such converted filtes, I got the following error.
ValueError: max(): Argument #1 ($value) must contain at least one element in max() (line 1209 of /var/www/html/vendor/dompdf/dompdf/lib/Cpdf.php)
Workaround: Download the .otf file but in @fontface declare it as truetype
@font-face { font-family: Maplestory; src: url('https://eclecticgeek.com/dompdf/fonts/Maplestory-Bold<strong>.otf</strong>') format('<strong>truetype</strong>') } * { font-family: Maplestory; }
Then go to entity print module configuration and disable "Font subsetting". The PDF will use the new font, but the file size will be very large (8 MB or more), which may not be desirable.
More info here: https://github.com/dompdf/dompdf/issues/932