16

I've spent a couple of days sifting through various methods to encourage FPDF to render the Euro symbol, but none have succeeded. I have:

$currency = iconv("UTF-8", "ISO-8859-1//TRANSLIT", '€');

Which results in:

iconv() [function.iconv]: Detected an incomplete multibyte character in input string

I've tried a variety of encoding types, but to no avail.

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
Wayne Smallman
  • 1,690
  • 11
  • 34
  • 56

4 Answers4

49

You actually can generate a PDF with euro signs using FPDF with using euro ascii code: chr(128).

It's good practice to make this a constant. At the top of your script, add:

define('EURO',chr(128));

Now you can use EURO in your script to print the euro symbol. For example:

"Costs: ".EURO.100

Will output: Costs: €100

Note: This will also work for other symbols with chr(ascii), where ascii is the ascii code of the symbol.

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
  • 2
    Why not just `"Costs: " . chr(128)`? Also, this should be the accepted answer, not the one promoting a different extension. – kasimir Oct 29 '14 at 12:24
  • 3
    Because `chr(128)` does not make any sense to someone whose reading your code. `EURO` does. You can upvote the answer if you like it to be the accepted answer. – Gerard de Visser Oct 29 '14 at 12:36
  • `chr(128)` makes sense to me... I think my gripe is that your answer starts with instructing us to define it as a constant, where I would see that as 'optional'. You could just as well define it as a variable, or use a function or what not. The key is getting the symbol by using the `chr` function. I think your answer should focus on that. – kasimir Oct 30 '14 at 09:00
  • 3
    This is much better than using an extension. I need to add the pound sign, (£) which is `chr(163)` if anyone was wondering. – Chud37 Apr 15 '15 at 12:22
  • The trouble I'm having with this answer is that ASCII actually ends at 127. Anything above is a subject to several non-compatible extensions. While this solution will work on most systems with Windows-12xx codepages, it might break somewhere else. – Mchl Feb 02 '16 at 07:04
10

I've searched for ages, and nothing worked - until I used this: utf8_encode(chr(128))

Zaph
  • 101
  • 1
  • 3
0

the iconv function worked for me

$text = "String with € sign"    
$pdfobj->Write(0,iconv('UTF-8', 'windows-1252', $text));
termigrator
  • 159
  • 3
  • 11
-3

if You Want to show this line "£4.30" just follow bellow

$text = chr(163); $pound = $text."4.30 p m";

Note: 163 = pound code;