1

I came across jsNode library here Generate pdf from HTML in div using Javascript So I've installed. I'm tryna use it to print a leaflet map. It seems I was not able to set it propely. It create the PDF but nothing shows on the map. Could you help me with that ?

Javascript

function genPDF() {

    var doc = new jsPDF();
    var elementHandler = {
        '#ignorePDF': function(element, renderer) {
            return true;
        }
    };
    var source = window.document.getElementsByTagName("div")[0];
    doc.fromHTML(
        source,
        15,
        15, {
            'width': 180,
            'elementHandlers': elementHandler
        });

    doc.output("dataurlnewwindow");

}

HTML

<html>
    <body onload="Create_MAP();">
        <div id="map">
        </div>
        <input type="button" class="bt" value="PRINT PDF" onclick="genPDF();">
    </body>
</html>
Community
  • 1
  • 1
Jason Krs
  • 704
  • 2
  • 9
  • 30

1 Answers1

0

You need to turn your leaflet map into an image first.

You can use https://github.com/mapbox/leaflet-image

Then add that image to jsPDF for export.

Dennis Bauszus
  • 1,624
  • 2
  • 19
  • 44