Van Coding
Van Coding

Reputation: 24534

wkhtmltopdf - Disable page breaking

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?

Upvotes: 8

Views: 5486

Answers (2)

James
James

Reputation: 25513

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.

Upvotes: 4

Alien Technology
Alien Technology

Reputation: 1838

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>

Upvotes: 1

Related Questions