8
votes

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

I think the problem is, that the map is built with tiles. The tiles are bigger than the map and are cut off, but wkhtmltopdf seems to ignore this and thinks that the cut off tiles also must fit onto the page...

Here's some sample code to reproduce this:

<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 it to PDF:

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

I'm using the latest version of wkhtmltopdf by the way...

Is there a possibility to make the map fill the page without the cut?

2
i'm facing a similar problem - did you have any luck finding the solution? My issue is that an image placed towards the bottom of the page is for no reason transported to the next page even though it could easily fit.user961627
@user961627 sadly, no. I've given up the search, but if you find something for your problem, it would be nice if you shared it with me :)Van Coding

2 Answers

4
votes

You can use the --page-width and --page-height options to wkhtmltopdf to specify a size with the same aspect ratio as the page. You'll probably still have to combine this with specifying a width and height on the body, but it's useful if you want to completely fill the output PDF with content.

For reference, the 'UnitReal' accepted by the --page-width and --page-height options accept 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 both be specified with the same unit.

1
votes

It's not really disabling page breaks, but setting a body height does render your map on just one page.

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