CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Special characters not encoded correctly when creating printable letters (PDF)
Pages: [1]

Author Topic: Special characters not encoded correctly when creating printable letters (PDF)  (Read 19375 times)

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Special characters not encoded correctly when creating printable letters (PDF)
February 01, 2011, 10:34:35 am
If I have a user with special characters like æ, å or ø or umlaut in their name, and select "Create Printable Letters (PDF)" the name is printed like this "Ã…lice Ægdav".

I am using version 3.3.3, and it happens both locally and at drupal.demo.civicrm.org

Do you guys know how to fix this issue? Thanks in advance!

A related post: http://forum.civicrm.org/index.php/topic,14957.0.html

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 01, 2011, 11:01:47 am
Hi,

did experiment the same issue indeed.

http://www.tcpdf.org/

The library used is supposed to handle utf8, as civi uses internally.

It would be create if you could investigate at what point the text get fubared. Looks like it's latin1 that is read as utf8 (or vice versa)

Quote from: resga on February 01, 2011, 10:34:35 am
If I have a user with special characters like æ, å or ø or umlaut in their name, and select "Create Printable Letters (PDF)" the name is printed like this "Ã…lice Ægdav".

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 01, 2011, 12:42:53 pm
I am very willing to investigate, do you have any suggestions where I should start?
Should I perhaps be looking at the Utils.php file in the sites/all/modules/civicrm/CRM/Utils/PDF folder? Or the database? It is utf8_unicode_ci if that makes any difference...

Thank you for the quick answer!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 01, 2011, 05:07:09 pm

the function that generates the PDF is:

CRM_Utils_PDF_Utils::html2pdf

which is called from:

CRM/Contact/Form/Task/PDFLetterCommon.php (line 272 or so)

if you do fix it, please post your solution here so we can incorporate it into the codebase

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 03, 2011, 02:02:13 pm
I found this suggestion somewhere, and now æ, å, ø, é, ü, ñ and other special characters work in printable letters (PDF):

Change line 145 in modules/civicrm/CRM/Utils/PDF/Utils.php from
$dompdf->load_html( $html );
  to
$dompdf->load_html( utf8_decode( $html ) );

I haven't made a patch before, so I hope I haven't messed up too badly...

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 03, 2011, 02:37:27 pm

great debugging and fix :)

can you please file an issue: http://issues.civicrm.org/ and attach this patch. We'll merge it into the 3.4 branch

thanx

lboo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

resga

  • I post occasionally
  • **
  • Posts: 38
  • Karma: 3
  • CiviCRM version: 3.4.2
  • CMS version: Drupal
  • MySQL version: 5.1.41
  • PHP version: 5.3
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 04, 2011, 01:14:12 am
I have opened an issue here: http://issues.civicrm.org/jira/browse/CRM-7495
Thank you for helping  :D

Armen

  • I’m new here
  • *
  • Posts: 7
  • Karma: 0
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 28, 2011, 07:14:46 am
Quote
Change line 145 in modules/civicrm/CRM/Utils/PDF/Utils.php from
$dompdf->load_html( $html );
  to
$dompdf->load_html( utf8_decode( $html ) );
Membership Report (Detail)
PDF

In Russian is not working.
Петров, Сидоров, Самойлов.

CiviCRM 3.3.1

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Special characters not encoded correctly when creating printable letters (PDF)
February 28, 2011, 08:14:27 am
Hi,

utf8_decode only works for latin1 (western europe) unfortunately.

I seems that there is an optional param to set the encoding on load_html, but couldn't find the syntax. Could you look at the code or try googling it ?

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

diablodale

  • Guest
Re: Special characters not encoded correctly when creating printable letters (PDF)
July 31, 2011, 05:20:37 pm
You may experience a problem with this workaround. For example, the EURO character will fail. utf_decode() converts the data into ISO-8859-1 charset. But ISO-8859-1 charset does not contain the EURO sign, therefor the EURO sign will be erroneously converted into a question mark character '?'

In order to convert properly UTF8 data with EURO sign you must use iconv()

Therefore, in modules/civicrm/CRM/Utils/PDF/Utils.php, find the line that has:
   $dompdf->load_html( $html );
or
   $dompdf->load_html( utf8_decode( $html ) );

Change this line to be:
   $dompdf->load_html(iconv("UTF-8", "CP1252", $html));

This resolved the problem of the EURO sign not appearing in PDFs on civicrm 4.0.4 on drupal 7.7.
I acknowledge that this will likely not work for characters outside CP1252. However, perhaps this now gives you a place to hack in (insert) your own character set.
I also hope that this will be as good (maybe better) than the utf8_decode() method previous used in various versions.

Would someone please verify this on their setup?

-kf-

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.1.3
  • CMS version: D7
  • MySQL version: 5.5
  • PHP version: 5.3
Re: Special characters not encoded correctly when creating printable letters (PDF)
August 06, 2012, 01:19:40 pm
I did the following to make this work for cyrillic, b/c dompdf 0.6 beta3 includes dejavu fonts for other UTF-8 langs.

1) manually upgraded to dompdf version 448 (0.6 beta3)
--> remove entire /packages/dompdf directory, replace with code.google.com/p/dompdf/downloads/list 0.6 beta3
2) modified /CRM/Utils/PDF/Utils.php to add <body style=\"font-family: 'dejavu serif'\"> at line 77,
3) change /CRM/Utils/PDF/Utils.php line 108 to     $dompdf->load_html($html);
4) change /packages/dompdf/dompdf_config.inc.php line 210 to def("DOMPDF_DEFAULT_FONT", "dejavu serif");
5) then don't use the WYSIWYG editor to override fonts in the letter

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Internationalization and Localization (Moderators: Michał Mach, mathieu) »
  • Special characters not encoded correctly when creating printable letters (PDF)

This forum was archived on 2017-11-26.