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

Karem
  • 17,615
  • 72
  • 178
  • 278
  • for me, changing the font did the work as the font library I was using doesn't have unicodes for other languages. – anuj arora Aug 30 '18 at 12:07

3 Answers3

7

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

Vladan
  • 725
  • 8
  • 13
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...

Erik A. Brandstadmoen
  • 10,430
  • 2
  • 37
  • 55
  • 1
    @ErikABrandstadmoen did not work out and i have changed this encoding parameter to UTF-8.. Still nothing.. Is there other places where you can change the encoding? or maybe the pdf libraries it selves only accepts iso-8859s ? – Karem Sep 04 '11 at 20:00
  • I am too looking for solution of the same problem. I tried above but it doesn't work. –  Feb 10 '14 at 09:59
1

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

Antoine Subit
  • 9,803
  • 4
  • 36
  • 52