UTF-8 czech characters

1,190 views
Skip to first unread message

Nikita Zaraka

unread,
Mar 7, 2012, 8:04:05 AM3/7/12
to dompdf
Hello,
I have problem with creating PDF file with international czech
characters.
Here are symbols I want to get
ěščřžýáíéúůó
dompdf create this
?š??žýáíéú?ó
And code is here
[code]
ob_start();
require_once("dompdf/dompdf_config.inc.php");

$content = '
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="charset=utf-8" />
</head>
ěščřžýáíéúůó
</body></html>';

$pdf = new DOMPDF();
$pdf->load_html($content);
$pdf->render();
$pdf->stream("file.pdf");
ob_end_flush();
[/code]

I have tried thing like using iconv "UTF-8" to "ISO-8859-2",
utf_decode... no success. I don't thing there will be problem with
fonts, because that deja-vu font included in dompdf print those
characters just fine.
I'm really stuck with this, any help would be appreciated.
Nikita

BrianS

unread,
Mar 7, 2012, 11:01:32 AM3/7/12
to dom...@googlegroups.com
You haven't actually told DOMPDF to use one of the DejaVu fonts. If you don't do this DOMPDF will default to one of the core fonts (Helvetica, Times, Courier). The core fonts currently only support Windows ANSI encoding, which is why some of your characters are converted to "?".

To display the characters correctly you should try something like the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html/loose.dtd">

<html>
<head>
  <meta http-equiv="Content-Type" content="charset=utf-8" />
  <style>
    body { font-family: dejavu sans, sans-serif; }
  </style>
</head>
<body>
  <p>ěščřžýáíéúůó</p>
</body>
</html>

See how I have specified that the document body uses DejaVu Sans as the font. That's what you're missing.

Nikita Zaraka

unread,
Mar 7, 2012, 3:12:34 PM3/7/12
to dompdf
thx! I thought deja vu font is set by default. Now everything
works :).
Reply all
Reply to author
Forward
0 new messages