Wkhtmltopdf - Disable Page Break

I am trying to embed a google map in a landscape PDF, but somehow wkhtmltopdf always cuts the map into two parts, although the map will easily fit on one page.

I think the problem is that the map is built using slabs. The tiles are larger than the map and are cropped, but wkhtmltopdf seems to ignore this and think that the cut tiles should also fit into the page ...

Here is a sample code to play:

<html> <head> <script src="https://maps.google.com/maps/api/js?sensor=false"></script> <script> window.onload = function(){ var fenway = new google.maps.LatLng(47.188563,8.480487); var gmap = new google.maps.Map(document.getElementById("map"),{ center: fenway, zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true }); var marker = new google.maps.Marker({ position: fenway, map:gmap }); google.maps.event.addListener(gmap,"tilesloaded",function(){ window.status = "ready"; }); } </script> </head> <body> <div id="map" style="width:1500px;height:800px"></div> </body> </html> 

And the command to convert to PDF:

wkhtmltopdf --window-status ready --orientation landscape map.html map.pdf

I am using the latest version of wkhtmltopdf, by the way ...

Is it possible to make the map fill the page without a cut?

+8
wkhtmltopdf
source share
2 answers

This does not disable page breaks, but setting the height of the body makes your map on only one page.

 <body style="height:1000px;"> <div id="map" style="width:1500px;height:800px;"></div> </body> 
+1
source share

You can use the --page-width and --page-height wkhtmltopdf for wkhtmltopdf to specify the size with the same aspect ratio as the page. You probably still have to combine this with an indication of the width and height of the body, but this is useful if you want to completely fill out the output PDF with the content.

For reference, "UnitReal", accepted with the --page-width and --page-height options, takes floating point values ​​with units:

 (none) == mm mm cm == 10mm m == 1000mm didot inch in == inch pica pc == pica cicero pixel px == pixel point pt == point 

But note that they must be specified with the same block.

+4
source share

All Articles