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

For a while now, I have used wkhtmltopdf for on-the-fly generation of pdf documents, and generally it i

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745532941a4631776.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信