I am using tFPDF to generate a PDF. The php file is UTF-8 encoded.
I want ©
for example, to be output in the pdf as the copyright symbol.
I have tried iconv
, html_entity_decode
, htmlspecialchars_decode
. When I take the string I am trying to decode and hard-code it in to a different file and decode it, it works as expected. So for some reason it is not being output in the PDF. I have tried output buffering. I am using DejaVuSansCondensed.ttf
(true type fonts).
Link to tFPDF: http://fpdf.org/en/script/script92.php
I am out of ideas. I tried double decoding, I checked everywhere to make sure it was not being encoded anywhere else.
Help!
Actully, fpdf project FAQ has an explanation for it:
http://www.fpdf.org/~~V/en/FAQ.php#q7
So, as emfi suggests, a combination of iconv() and html_entity_decode() PHP functions is the solution to your question:
You can also use
setFont('Symbol')
orsetFont('ZapfDingbats')
to select the special characters that you want to print.Output: √
This way, you won't need to convert to ISO-8859-1 or Windows-1252 OR use another library tFPDF for special characters :)
Refer: http://www.fpdf.org/en/script/script4.php for font & character list
I have fix the problem with this code:
I'm pretty sure there is no automatic conversion available from HTML entity codes to their UTF-8 equivalents. In cases like this I have resorted to manual string replacement, eg:
you need this:
the html_entity_decode decodes the html entities. but due to any reason you must convert it to utf8 with iconv. i suppose this is a fpdf-secret... cause in normal browser view it is displayed correctly.