Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf wait for condition before printing

We are using wkhtmltopdf to convert dynamic html pages to pdf. We need to wait until all the ajax requests are finished.

Is there a possibility to delay the printing by a condition?

like image 329
Levi Avatar asked May 14 '14 08:05

Levi


2 Answers

You can use the --window-status option, see this post on the mailing list.

like image 77
ashkulz Avatar answered Oct 23 '22 15:10

ashkulz


If you can change the javascript code of the webpage then add this line of code to your javascript when you are certain everything is done loading:

if (your_condition_is_met_here){
    window.status = 'ready_to_print';
}

Then pass a flag --window-status ready_to_print to wkhtmltopdf. For example:

wkhtmltopdf --window-status ready_to_print map.html map.pdf

See: wkhtmltopdf javascript delay for output of google maps

like image 38
Eric Leschinski Avatar answered Oct 23 '22 15:10

Eric Leschinski