Im trying to create pdf with correct characters, but there are "?" chars. I created a test php file, where Im trying to fing the best solution. If Im open in the browser the html I looks like ok
UTF-8 --> UTF-8 : X Ponuka číslo € černý Češký
But when I look into the pdf I see this
UTF-8 --> UTF-8 : X Ponuka ?íslo € ?erný ?ešký
Here is my all code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>č s š Š</title>
</head>
<body>
<?php
require_once("dompdf/dompdf_config.inc.php");
$tab = array("UTF-8", "ASCII", "Windows-1250", "ISO-8859-2", "ISO-8859-1", "ISO-8859-6", "CP1256");
$chain = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style></style><title>č s š Š</title></head><body>';
foreach ($tab as $i)
{
foreach ($tab as $j)
{
$chain .= "<br> $i --> $j : ".iconv($i, $j, 'X Ponuka číslo € černý Češký <br>');
}
}
$chain .= '<p style="font-family: firefly, verdana, sans-serif;">??????X Ponuka číslo € černý Češký <br></p></body></html>';
echo $chain;
echo 'X Ponuka číslo € černý Češký <br>';
$filename = 'pdf/_1.pdf';
$dompdf = new DOMPDF();
$dompdf->load_html($chain, 'UTF-8');
$dompdf->set_paper('a4', 'portrait'); // change these if you need to
$dompdf->render();
file_put_contents($filename, $dompdf->output());
?>
</body>
</html>
What Im doing wrong? I tried many many options which I found :( Any idea?
I got UTF-8 characters working with this combination. Before you pass html to DOMpdf, make encoding covert with this:
Use DejaVu font in your css
Make sure you have set utf-8 encoding in HTML
<head>
tagNow all special characters are working "ľ š č ť ž ý á í é"
Nothing out of mentioned answers helped me. After hours of struggle I switched to niklasravnsborg/laravel-pdf has nearly exactly the same syntax and usage, and everything is working allright.
I had similar problem and ended up using tcpdf.Hope this could be helpful. http://www.tcpdf.org/
Problem was the font i was using.I was able to get the correct output using this font 'freeserif'.I guess it might be possible to get the same output using this font with dompdf.
Here is the sample i have used. tcpdf utf-8 sample
You should read over the Unicode How-to again. The main problem is that you don't specify a font that supports your characters. It looks like you've read the how-to, because you're using the font example from that document. However the example was not meant to apply globally to any document, dompdf doesn't include firefly (a Chinese character font) or Verdana by default.
If you do not specify a font then dompdf falls back to one of the core fonts (Helvetica, Times Roman, Courier) which only support Windows ANSI encoding. So always be sure to style your text with a font that supports Unicode encoding and has the characters you need to display.
With dompdf 0.6.0 you can use the included Deja Vu fonts. So the following should work (just the HTML):
Chinese characters are causing problems sometimes. The important part is to have good font here is a list you can download.
I chose first named "Kai Bold Font" here is a download page
Then put it on your hosting service in a public folder. I put it into
and here is my html example
PS. there is a little chance you might need this set:
If you don't mind having only one charset you can change every charset in
dompdf_font_family_cache.dist.php
just like
I know it's not the best way, but it saves lot of time