wkhtmltopdf wait for condition before printing
Asked Answered
E

3

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?

Extrauterine answered 14/5, 2014 at 8:47 Comment(2)
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.Dyl
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.Extrauterine
R
23

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

Roundly answered 15/5, 2014 at 6:52 Comment(0)
K
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

Kootenay answered 22/12, 2018 at 3:22 Comment(0)
A
0

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

Alphanumeric answered 14/5, 2014 at 8:54 Comment(1)
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.Extrauterine

© 2022 - 2024 — McMap. All rights reserved.