Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf not executing javascript

I'm trying to render a pdf of a html page. In the end of the HTML I have a very short jQuery script.

After wkhtmltopdf has been executed, it renders all the HTML fine however the Javascript has not been loaded for the PDF file. So it seems as if either wkhtmltopdf is ignoring my Javascript, or it is generating the .pdf before it is running the javascript.

I've tried both with $(document).ready and without, without results. I've tried --debug-javascript without any information retrieved.

Any ideas?

like image 965
Marcus Lind Avatar asked Jun 13 '13 10:06

Marcus Lind


People also ask

How do I debug Wkhtmltopdf?

Another (I would say easiest) means of debugging javascript in WKHTMLTOPDF is to download QT Browser, the underlying browser used by WKHTMLTOPDF, and to inspect the javascript execution for your page from within the browser. You can basically debug your JavaScript in QT Browser just as you would in Chrome or Firefox.

What is Wkhtmltopdf EXE?

What is it? wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service. There is also a C library, if you're into that kind of thing.


1 Answers

SOLVED: I solved this issue by using pure Javascript instead of using jQuery. I tried loading jquery.min.js, normal jquery.js and also making sure it was on the same host as I was running wkhtmltopdf from. Nothing worked.

When I instead used normal javascript it was running fine.

like image 195
Marcus Lind Avatar answered Sep 28 '22 07:09

Marcus Lind