Having æøå chars in HTML2PDF charset

喜欢而已 提交于 2020-01-31 18:02:30

问题


$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:

  1. Set 'UTF-8' encoding, as already suggested by Erik
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!