简体   繁体   中英

jsPDF settings for printing leaflet/openlayers map

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM