0

I have problem with Serbian language in FPDF http://www.fpdf.org/

$mystring = "Запослени у рачуноводству/сродном радном месту";

I used $pdf->Write and MultiCell... all are same result.

utf8_decode($mystring) -> ????????? ? ?????????????/??????? ?????? ?????

iconv('UTF-8', 'utf-8//TRANSLIT', $mystring) -> ЗапÐ3⁄4ѕлÐμÐ1⁄2Ð ̧ у рачуÐ1⁄2Ð3⁄4Ð2Ð3⁄4Ð ́ѕтÐ2у/ѕрÐ3⁄4Ð ́Ð1⁄2Ð3⁄4Ð1⁄4 раР́Ð1⁄2Ð3⁄4Ð1⁄4Ð1⁄4Ðμѕту

thank so much

ca michel
  • 105
  • 2
  • 8
  • What charset is the string in `$mystring`? Only if its's in ISO-8859-1 should you call `utf8_decode()` ([see also this](https://wiki.php.net/rfc/remove_utf_8_decode_encode)). And your call to `iconv()` tries to convert from utf-8 to utf-8 (I dont't think `//TRANSLIT` makes sense for utf-8, as utf-8 should already be able to encode all characters). – Karsten Koop Jul 19 '18 at 11:02

1 Answers1

1

Personally I would not use UTF-8 in my PDFs because the file size will big for me. I use font embedding in this case to avoid big file size.

The FPDF class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. UTF-8 support is also available.

For the UTF-8 support you have to use tFPDF which is based on FPDF. tFPDF accepts UTF-8 encoded text. Please read all this instructions and then download the ZIP file on the bottom from this site.

Convertation to UTF-8:

You do not need a convertation to UTF-8 if you use instructions above (from link) and load a UTF-8 string from a file like follows:

// this file file must be saved in UTF-8 before:
$str = file_get_contents('Text-saved-in-UTF-8.txt');

In other case:

You have to use mb_convert_encoding and not iconv.

For Serbian (Latin) this is either 'iso-8859-2' or 'windows-1250'. For Serbian (Cyrillic) this is 'iso-8859-5' or 'windows-1251'. These encodings will provide correct display of diacritic Latin characters such as žćđš.

In yor case for:

$mystring = "Запослени у рачуноводству/сродном радном месту";

You have to write:

$str = mb_convert_encoding($mystring, 'UTF-8', 'iso-8859-5');

or

$str = mb_convert_encoding($mystring, 'UTF-8', 'windows-1251');

Your PHP file must be saved in iso-8859-5 or in windows-1251 before (but not in UTF-8).

And then you use this in tFPDF.

Bharata
  • 13,509
  • 6
  • 36
  • 50
  • The both iso-8859-5 and windows-1251 are say ��������� � �������������/������� ������ ����� – ca michel Jul 19 '18 at 13:28
  • @camichel, I corrected my answer. Please delete your comments above. I have checked it on my server and it works. – Bharata Jul 19 '18 at 16:24