Search code examples
leafletwkhtmltopdf

wkhtmltopdf and leaflet wait for map


I'm using wkhtmltopdf for print my html code, this code has leaflet maps, my problem is pdf file doesnt't print the map properly, it seems it doesn't wait for the map, so I included a window-status condition without success:

In my html:

var myMap = L.map('myMap',{attributionControl: false, zoomControl:false })
    .on('load', function(){window.status = 'maploaded'});

My options for wkhtmltopdf:

 options = {
    'dpi': 300,
    'image-dpi': 400,
    'zoom': 0.7,
    'window-status': 'maploaded'
}

I check that the event is fired and the pdf is generated after it's fired, but I the map is not shown.

What should I do?


Solution

  • I finally solved this issue.

    The problem wasn't the time I was waiting for the map rendering but the size.

    An usual "javascript-delay" is enought for this. The problem:

    <div id="map" class="my-map">
          //leaflet code
    </div>
    
    .my-map{
    
        //not working
        //width: 80%; 
        //height:80%;
    
        //working
        width: 800px;
        height: 400px;
    }