wrong symbol exported in fpdf... ñ as ñ ..?
Asked Answered
S

4

7

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?

Sewellyn answered 9/1, 2011 at 9:52 Comment(2)
This is a character set issue. You need to add more detail: Where your data comes from (Database? Form?), how it is encodedRamin
database form.. but people write ñ and it ends up in fpdf as those symbols.. in the mysql database it appears how I want itSewellyn
E
8

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 ñ
Ebonee answered 9/1, 2011 at 9:59 Comment(3)
hey thnx! were do I echo that? .. like below, after what?Sewellyn
You have to use it before you write the strings into your PDF: $your_string = utf8_decode($your_string);. Actually directly after reading $_POST: $your_string = utf8_decode($_POST['your_string']);Ebonee
this is my post: $pdf->Write(0, "".$person["CA"]); should I do this: $pdf->Write $your_string = utf8_decode(0, "".$person["CA"]); ????Sewellyn
B
2

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!

Bermuda answered 10/2, 2012 at 8:54 Comment(0)
C
1

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");
Cheju answered 9/1, 2011 at 9:59 Comment(0)
P
1

The alternative solution would be to extend FPDF with Unicode (UTF-8) support. There is a patch for that: http://acko.net/node/56

Pettigrew answered 9/1, 2011 at 10:0 Comment(4)
thnx for responding!! ..how do i install it?Sewellyn
@NORM: Really: I have no clue. But from what I've gathered, you just use it in place of the normal FPDF. Change the include, and instantiate the new UFPDF() class.Pettigrew
@Edson: Internet Archive: web.archive.org/web/20110411183526/http://acko.net/node/56Pettigrew
acko.net/node/56 is not validObtuse

© 2022 - 2024 — McMap. All rights reserved.