Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wkhtmltopdf OpenLayers V3 failed

I try to generate a PDF with wkhtmltopfd from an OpenLayer V3 map, but I get only an empty image.

This code should generate a PDF with the map images, but it generates only the background of the map.

wkhtmltopdf --javascript-delay 5000 http://openlayers.org/en/v3.1.1/examples/moveend.html test.pdf

What am I doing wrong?

This is what I have already checked:

  • I opened the webpage with Chrome and saved it to a PDF. It works.
  • In the Wireshark trace I can't see any request to a tile image (so a blocking tile server is not the failure).
  • I tried some options on wkhtmltopdf like --background and --images, but with no success (these options are also marked as default options).
  • I'm using wkhtmltopdf 0.12.1.2 (with patched qt) on Windows 8. No success.
  • Also wkhtmltopdf 0.12.1 (with patched qt) on Ubuntu 14: no success.
like image 531
powerpete Avatar asked Nov 10 '22 20:11

powerpete


1 Answers

Use window status switch "--window-status XXXX", If you add this switch the PDF component (wkhtmtopdf) will wait for the window-status , As soon as script set the window sataus to ready or anything given in the switch wkhtmltopdf start converting the html to PDF.

What you need to do…. Try to find when your maps are loaded in DOM and everything got rendered (ajax calls or any long running script has been done/succeeded) then set the window.sataus = "ready" (using java script)

add the switch "--window-status ready"

wkhtmltopdf --window-status ready http://openlayers.org/en/v3.1.1/examples/moveend.html test.pdf

like image 133
Ihtsham Minhas Avatar answered Nov 15 '22 12:11

Ihtsham Minhas