问题
$content = "ÆØÅ";
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->writeHTML($content, false)
$html2pdf->Output('', 'S'));
Gives me a PDF file with "ÆØÃ"
I checked the encoding in html2pdf.class.php and it is set to UTF-8 which should be fine.
I tried to change 'en' to 'da' (danish), still same result..
How can i fix this please? Spent hours now looking..
回答1:
You have to do two things to see strange UTF8 characters in html2pdf:
- Set 'UTF-8' encoding, as already suggested by Erik
- Use the only UTF-8 font in html2pdf:
freeserif
I know it's old question, but I need some points :)
回答2:
Looks like you are specifying the wrong output encoding. The output is typical of what you'd get if trying to show UTF-8 output as ISO8859-1, for example.
Looks like the HTML2PDF constructor also has a version that takes a character encoding as the parameter:
$html2pdf = new HTML2PDF('P','A4','da', true, 'UTF-8');
could possibly work...
回答3:
You can use this PHP function
utf8_decode($article_content);
If it doesn't work the only solution is to make a str_replace()
$content = "ÆØÅ";
$code_html = array("Æ","Ø","Å");
$caract_sp = array("Æ","Ø","Å");
str_replace($code_html, $caract_sp, $content);
For any other specials characters you can see the equivalents HTML codes here : http://www.toutimages.com/codes_caracteres.htm
来源:https://stackoverflow.com/questions/7301310/having-%c3%a6%c3%b8%c3%a5-chars-in-html2pdf-charset