I dont know whats the problem but whenever I call the letter ñ from $_POST function it puts it in my fpdf as ñ .. any idea why?
Your string has a wrong encoding. It's UTF-8 but I think you need Latin-1 or so..
You can use utf8_decode() on your strings:
echo utf8_decode("ñ"); // prints ñ
$your_string = utf8_decode($your_string);
. Actually directly after reading $_POST: $your_string = utf8_decode($_POST['your_string']);
–
Ebonee I too have spent a fair amount of time trying to get this to work and thought the following explanation might be helpful for others.
No need to write your own complex functions if the only problem is a £/€
or similar character.
Here's what I have used (taken from this thread and others on the net):-
$pdf->SetY(220); // set the y co-ord before output //
$monthlyRent = utf8_decode("£" . number_format($monthlyRent, 2)); // 2 dec places //
// previously $monthlyRent is pulled from the MySql db as $array['_monthlyRent'];
$pdf->Write(5,'Gross monthly rent: ' . $monthlyRent); // outputs £980 or whatever. //
Works a treat but do remember to do the number_format($yourval, 2)
in the same line as the utf8_decode();
or it screws up!
Hope this is helpful to some poor sod, who like me, has struggled for a few hours!
We had the problem once and using
utf8_decode("foo bar");
solved the problem (depends of course if the data is comming from the user, a database,...). Don't forget to deliver the file to the user in UTF-8 as well in the header
header("Content-type: application/pdf; charset=utf-8");
The alternative solution would be to extend FPDF with Unicode (UTF-8) support. There is a patch for that: http://acko.net/node/56
new UFPDF()
class. –
Pettigrew © 2022 - 2024 — McMap. All rights reserved.