Generate PDF on the server from Google Maps API?
We have a hosted web app that uses the Google Maps API for various types of geographical reports, using a combination of the javascript API for adding markers and shapes, plus KML overlays for other layers.
There's some demand from customers for turning these into n开发者_JAVA技巧ice downloadable & printable PDF maps. I'm not sure where to begin with that. Any ideas?
As Mark Storer pointed out, you can use wkhtmltopdf.
If you have polylines or other stuff in your map you will likely need wkhtmltopdf to wait for all the pieces to be in place before generating the PDF. This can be done with the latest version 0.10.0_rc2 and with the --window-status parameter (javascript in your target page will have to update the window.status variable once everything is ready).
Check out the manual here
An example usage goes like this:
wkhtmltopdf.exe --page-size A4 --dpi 600 --window-status ready --print-media-type http://www.yoursite.com/target.html target.pdf
Cons: the whole process is a bit overkill in terms of resources, so if your webapp gets plenty of hits you may want to pay close attention to this aspect.
Once you work out all the legal details, I recommend looking at wkthmltopdf. It will accurately evaluate the page's JavaScript, critical to any Google Map web page.
You will need a Premier license with Google otherwise you will be breaking the Terms of Service
精彩评论