5

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?

cucuru
  • 3,456
  • 8
  • 40
  • 74

1 Answers1

2

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;
}
cucuru
  • 3,456
  • 8
  • 40
  • 74
  • I am having problems printing leaflet maps with wkhtmltopdf. The map box and controls are showing but the tile layer is not loading properly, nor the geometries I just added to me Map> Could you give me a full code example of how you could print a leaflet map with wkhtmltopdf. I posted I question here: https://stackoverflow.com/questions/75250265/how-to-print-leaflet-map-in-pdf-using-django-wkhtmltopdf – Ernesto Ruiz Jan 30 '23 at 17:38