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';
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.
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';
I had a similar problem with wkhtmltopdf before where the Chinese characters were not rendered properly. I have solved the problem by installing the appropriate Chinese fonts.
By any chance do you have to install any Czech related fonts for the characters to render properly? As I am not familiar with Czech characters / fonts, I am not sure whether this applies. Hope this helps.
Just now I made a test with those characters you provided and they work fine for me. Win7, wkhtmltopdf 0.11.0 rc2. Works on cover, toc, bookmarks, content and headers. Also tested with korean and chinese characters and even they work.
PDF Generated using (file locations removed)
--print-media-type --page-size A5 --header-html header.html --footer-html footer.html --margin-bottom 10mm --margin-top 10mm --margin-left 10mm --margin-right 10mm cover cover.html toc --xsl-style-sheet tocfile.xsl temp.html temp.pdf
temp.html is Extremely invalid XHTML, first line says <?xml version="1.0" encoding="iso-8859-1"?>
. The temp.html file was written to disk with C# using UTF-8 and it works. I really suggest using UTF-8 wherever possible.
来源:https://stackoverflow.com/questions/11859872/wkhtmltopdf-encoding-issue