Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf - encoding issue

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';
like image 992
Michal S Avatar asked Aug 08 '12 07:08

Michal S


2 Answers

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.

like image 55
Marcel Burkhard Avatar answered Sep 24 '22 04:09

Marcel Burkhard


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';
like image 20
Michal S Avatar answered Sep 21 '22 04:09

Michal S