Reputation: 11
I have an bosnian string $string = "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul."
I used "Write" function of fpdf http://www.fpdf.org/ but all "č" characters become to "è"
$pdf->Write (6, iconv('UTF-8', 'CP1250//TRANSLIT', "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul."));
How can I fix it? thank so much!
Upvotes: 1
Views: 968
Reputation: 14175
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 a 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.
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 Bosnian (Latin) this is 'iso-8859-2'
.
In yor case for:
$mystring = "Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul.";
You have to write:
$str = mb_convert_encoding($mystring, 'UTF-8', 'iso-8859-2');
Your PHP file must be saved in iso-8859-2
before (but not in UTF-8).
And then you use this in tFPDF.
Upvotes: 0
Reputation: 6809
Something like this should work:
require_once 'fpdf181\fpdf.php';
require_once 'fpdf181\makefont\makefont.php';
MakeFont('C:\\Windows\\Fonts\\arial.ttf','cp1252');
$pdf = new FPDF();
$pdf->AddFont('Arial','','Arial.php');
$pdf->AddPage();
$pdf->SetFont('Arial','',16);
$pdf->Write(6,'Saglasno odredbama čl.19 Zakona o udruženjima i Statuta Udruženja računovođa i knjigovođa Srbije URIKS iz Beograda, ul.');
$pdf->Output();
Try to change the encoding to cp1250
or ISO-8859-2
.
Source: http://www.fpdf.org/en/tutorial/tuto7.htm
If all this should fail then try to use UTF-8: http://www.fpdf.org/en/script/script92.php
Upvotes: 1