Entity print with dompdf not printing polish characters

Created on 14 July 2023, 12 months ago
Updated 17 August 2023, 11 months ago

I am using Drupal 9 and Entity Print for printing forms created by Webform. After updating Drupal and modules, Entity Print changed the font and does not display Polish characters. Here's what I have tried so far:

In the form configuration, under webform -> settings -> general -> third party settings -> entity print -> css, I set different fonts. However, Entity Print only provides options between serif and sans-serif.

In the Entity Print settings, I have enabled "default CSS." I edited the file modules/contrib/entity-print/css/entity-print.css to add configuration for a different font, but it didn't work.

I edited the entity-print.html.twig file. It is set to use UTF-8 encoding by default, but changing it to, for example, ISO-8859-2, didn't help.

I tried the solution mentioned in this link: https://www.drupal.org/project/entity_print/issues/3011414 🐛 Dompdf not rendering Russian / cyrillic characters Needs review , but it also didn't work.

Any solution that allows me to have the font declared in the CSS for the print output would be satisfactory.

🐛 Bug report
Status

Active

Version

2.13

Component

Miscellaneous

Created by

🇵🇱Poland el35

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 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

Production build 0.69.0 2024