Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
882 views
in Technique[技术] by (71.8m points)

wkhtmltopdf javascript delay for output of google maps

I am working with WKTHMTOPDF and really enjoying it. However, the page that is being converted has google maps and the resulting PDF comes out with the map half loaded. I know there was an option to add --javascript--delay in previous versions, but it would appear it is deprecated. I am using version 0.99. Is there a different option?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is another a better way to do this that does not require using --javascript--delay (and has the advantage of not requiring you to set a delay time before you know what the required delay will actually be).

Add a callback to the 'tileloaded' event:

google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
   window.status = 'ready_to_print';
});

Then call wkhtmltopdf with the --window.status option set to 'ready_to_print' e.g.

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

obviously you can change the string 'ready_to_print' to be whatever you want so long as window.status does not already equal that value when wkhtmltopdf is called and before the above code fires.

A similar approach can be used with google charts, though the appropriate event goes by a different name.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...