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?
The page-break-before property adds a page-break before a specified element.. Tip: The properties: page-break-before, page-break-after and page-break-inside help to define how a document should behave when printed. Note: You cannot use this property on an empty <div> or on absolutely positioned elements.
wkhtmltopdf is an open source (LGPLv3) command line tool to render HTML into PDF using the Qt WebKit rendering engine.
What is it? wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service. There is also a C library, if you're into that kind of thing.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With