wkhtmltopdf - encoding issue

Michal S picture Michal S · Aug 8, 2012 · Viewed 26.2k times · Source

I'm using wkhtmltopdf to export html pages to pdf, but it seems it has a problem with Czech characters... I load whole html into variable, then I change encoding and run wkhtmltopdf like this:

$html = ob_get_clean();
$html = iconv("UTF-8","Windows-1250", $html);
file_put_contents('../export.php', $html);

$commandString = WKHTML_LIB.'http://www.estiroad.com/export.php sestava.pdf';
exec($commandString);

The .html file has the right encoding, but even when I set --encoding windows-1250 parameter to command string, its just not working... Thanks for any ideas...

EDIT: I solved the issue! The catch was in constant WKHTML_LIB, which I defined on the beginning of the page:

define('WKHTML_LIB', "../wkhtmltopdf/wkhtmltopdf-amd64");

I just wrote the path directly to the exec(); command and now it works even with the flags. Sorry for bothering you with such a triviality... Now the $commandString line looks like this:

$commandString = '"../wkhtmltopdf/wkhtmltopdf-amd64" --print-media-type --page-size A4 -R     50 --encoding windows-1250 --header-html header.html --margin-top 10mm --margin-bottom 10mm --margin-left 10mm --margin-right 10mm http://www.estiroad.com/export.php sestava.pdf';

Answer

Marcel Burkhard picture Marcel Burkhard · Jun 27, 2014

For future reference:

I had the same problem with german umlauts.

As soon as I added

<meta charset="UTF-8" />

to the html page the problem was solved.

That of course presupposes your page is served as utf-8.