19

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?

Levi
  • 657
  • 2
  • 6
  • 14
  • I'm guessing there isn't an option for this because it breaks down when you think about it too much. Imagine a page that continuously polls an AJAX endpoint every N seconds, something that is actually very common. Your scenario might not have this but wkhtmltopdf doesn't know that and there's no real way to flag that you have a fixed load path. – Chris Haas May 14 '14 at 20:27
  • I don't want wkhtmltopdf to wait my ajax requests, I would need an option to add my wait condition, maybe a script which can tell wkhtmltopdf when to print. – Levi May 15 '14 at 06:19

3 Answers3

23

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

sk8terboi87 ツ
  • 3,396
  • 3
  • 34
  • 45
ashkulz
  • 792
  • 3
  • 6
10

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

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
0

You can try using the --javascript-delay option.

Tim
  • 2,134
  • 3
  • 26
  • 40
  • I want to be sure that every request is finished and I don't want to delay more then needed. So --jvascript-delay is not good. – Levi May 14 '14 at 09:59