Having æøå chars in HTML2PDF charset
Asked Answered
R

3

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

Roethke answered 4/9, 2011 at 18:33 Comment(1)
for me, changing the font did the work as the font library I was using doesn't have unicodes for other languages.Giusto
R
8

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

Railey answered 30/4, 2015 at 20:12 Comment(3)
Just to clarify wrap the html entity for the symbol you need &#8364; for €, &#163; for £ etc. <span style='font-family: freeserif'>&#8364;</span> As explained here github.com/spipu/html2pdf/edit/master/examples/utf8.phpVat
This is just fix mine, but with the html meta tag. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>Corney
i found out that the problem happens on page_header and page_footer tagsIncontrollable
C
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...

Creative answered 4/9, 2011 at 19:34 Comment(2)
@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 ?Roethke
I am too looking for solution of the same problem. I tried above but it doesn't work.Steeplebush
R
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("&AElig;","&Oslash;","&Aring;");
$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

Roadster answered 10/12, 2013 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.