3

How to change the encoding in pdf documents? Cyrillic characters are not displayed in my pdf documents. To display them, you need to change the encoding. Please tell me which file can this be done? I tried to find the answer in other questions, but unfortunately I could not.

enter image description here

css

Report pdf

Report html

  • This needs to be fixed in CiviCRM – Vietyank Jul 24 at 3:56
6

I don't think it's the encoding it seems that none of the included fonts in dompdf support it. See also https://stackoverflow.com/questions/16384517/dompdf-character-encoding-utf-8. If you look in the vendor/dompdf/dompdf/lib/fonts folder there's a readme about DejaVu, and it says you can get the font from http://code.google.com/p/dompdf and copy it into your dompdf/lib/fonts folder. Then as the first link describes you need to change the font used by the Civi message template you're using, e.g. in the template under Administer - CiviMail - Message Templates if you edit the template you'll see either <font> tags or something like style="font-family: Arial", and you can change the font there. If you're pdf'ing reports you can edit css/print.css.

Note that clicking the .ttf files at the link above seem to be redirects to another page where you can actually download the real file. If you just save the .ttf files directly they aren't really ttf files.

Also in order to get it to recognize the .ttf I had to add this to the print.css file:

@font-face {
  font-family: 'DejaVu Sans';
  font-style: normal;
  font-weight: normal;
  src: url(https://mysite.org/path/to/civicrm/vendor/dompdf/dompdf/lib/fonts/DejaVuSans.ttf) format('truetype');
}
@font-face {
  font-family: 'DejaVu Sans';
  font-style: italic;
  font-weight: normal;
  src: url(https://mysite.org/path/to/civicrm/vendor/dompdf/dompdf/lib/fonts/DejaVuSans-Oblique.ttf) format('truetype');
}
@font-face {
  font-family: 'DejaVu Sans';
  font-style: normal;
  font-weight: bold;
  src: url(https://mysite.org/path/to/civicrm/vendor/dompdf/dompdf/lib/fonts/DejaVuSans-Bold.ttf) format('truetype');
}
@font-face {
  font-family: 'DejaVu Sans';
  font-style: italic;
  font-weight: bold;
  src: url(https://mysite.org/path/to/civicrm/vendor/dompdf/dompdf/lib/fonts/DejaVuSans-BoldOblique.ttf) format('truetype');
}
  • 1
    You're right there seems to be something still missing. – Demerit Dec 19 '18 at 23:11
  • 1
    I've updated answer. – Demerit Dec 20 '18 at 0:49
  • 1
    Yes it worked for me with russian letters. If you choose file - properties in the pdf and look at the fonts tab is it the right font? – Demerit Dec 20 '18 at 10:44
  • 1
    Is the url in @font-face correct for your site? If you put it into the browser bar does it download the ttf file? – Demerit Dec 20 '18 at 13:02
  • 1
    Some more things to check: 1. Earlier you said you converted to afm. Maybe move that file out of the way in case it is interfering. 2. If you choose "print report" instead of PDF, does it pick up the right styles when you check using your browser developer tools? 3. On the report page if you click on title and format, is the path to the print.css file correct in the @import tag (especially if on windows no backslashes). – Demerit Dec 20 '18 at 13:51

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.