最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How can I troubleshoot javascript or http errors in wkhtmltopdf? - Stack Overflow

programmeradmin0浏览0评论

For a while now, I have used wkhtmltopdf for on-the-fly generation of pdf documents, and generally it is far ahead of the pack (pared with other tools available in php).

However, it is a HUGE PAIN to do even the most basic debugging of this process. With your regular browser, one might alert(var); or console.log(var); and discover that "var" is undefined. Again, you can easily see a 404 or 500 http error somewhere in the browser console.

Take for instance this:

wkhtmltopdf.exe http://localhost/mypage.html C:/temp/myfile.pdf

The pdf file does get created but is imperfect because certain aspects dependent on javscript or AJAX are missing.

With wkhtmltopdf, how best can I investigate these kinds of errors, if they exist in mypage.html?

For a while now, I have used wkhtmltopdf for on-the-fly generation of pdf documents, and generally it is far ahead of the pack (pared with other tools available in php).

However, it is a HUGE PAIN to do even the most basic debugging of this process. With your regular browser, one might alert(var); or console.log(var); and discover that "var" is undefined. Again, you can easily see a 404 or 500 http error somewhere in the browser console.

Take for instance this:

wkhtmltopdf.exe http://localhost/mypage.html C:/temp/myfile.pdf

The pdf file does get created but is imperfect because certain aspects dependent on javscript or AJAX are missing.

With wkhtmltopdf, how best can I investigate these kinds of errors, if they exist in mypage.html?

Share Improve this question asked Sep 20, 2016 at 12:40 Ifedi OkonkwoIfedi Okonkwo 3,6665 gold badges35 silver badges45 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You need to use the --debug-javascript mand-line option. I tested it in Linux, but it's probably the same on Windows:

$ echo '<script>console.log("YAY!");</script>' > test.html
$ wkhtmltopdf --debug-javascript test.html test.pdf
Loading pages (1/6)
Warning: file:///tmp/test.html:1 YAY!
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

For 404 and 500 error, wkhtmltopdf should prints some stuff on the mand line too, if I remember well.

Seems to me you should just open the source page in your browser first. Your browser's debugger can trace the issues. Once you know the page is perfect, you can run it through wkhtmltopdf.

发布评论

评论列表(0)

  1. 暂无评论