Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having æøå chars in HTML2PDF charset

Tags:

php

html2pdf

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

like image 291
Karem Avatar asked Sep 04 '11 18:09

Karem


3 Answers

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

like image 67
Vladan Avatar answered Oct 17 '22 22:10

Vladan


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...

like image 2
Erik A. Brandstadmoen Avatar answered Oct 17 '22 22:10

Erik A. Brandstadmoen


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

like image 1
Antoine Subit Avatar answered Oct 17 '22 21:10

Antoine Subit