dompdf special characters

coffeemonitor picture coffeemonitor · Feb 27, 2011 · Viewed 34.1k times · Source

I'm having successful html-to-pdf conversions, but not with special characters.

Below is just a special character I'm trying to display, which displays in browsers on my Mac, when I put it simply inside an html document. (but not on my windows box)

<?php
require_once("../dompdf_config.inc.php");
$html = '&#8364;';
$dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("contract.pdf");
exit(0);
?>

I keep getting a "?" (question mark) when the pdf is rendered. I know there's been lots of issues documented with regards to special characters, but I thought I'd give this a try, with the code I'm actually using.

If DomPdf isn't a recommended html-to-pdf conversion tool, I'll take any other recommendations!

Answer

Ricardo Martins picture Ricardo Martins · Oct 10, 2012

I have experienced problems with DOMPDF when converting an UTF-8 html page. I simply solved the problem by adding

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Between < head > tag. Maybe it could be an alternative if you set it with your encoding type.

IMPORTANT NOTE from comments below: don't use stream() and output() methods on the same pdf instance. If you do this wont work.