I try to use javascript library JSPDF for export my OpenLayers map but it doesn't work. I create my HTML :

     <script type="text/javascript" src="script/ol_3.7.0/build/ol.js"></script>
     <script type="text/javascript" src="script/proj4js/dist/proj4.js"></script>
     <script type="text/javascript" src="script/jquery/jquery.js"></script>
     <script src="http://parall.ax/parallax/js/jspdf.js"></script>

     <div id = "index_map"></div>

     <div id = "editor"></div>
     <button id="cmd">generate PDF</button>

And my Javascript :

$(document).ready(function () {

    var doc = new jsPDF();

    var specialElementHandlers = {
        '#editor': function (element, renderer) {
            return true;

    $('#cmd').click(function () {

        var html=$("'#index_map").html();
        console.log (html);
        doc.fromHTML(html, 200, 200, {
            'width': 500,
                'elementHandlers': specialElementHandlers


And when I click on my button I've the message "doc.fromHTML is not a function"

enter image description here



doc.fromHTML($('#index_map').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers

note the get: doc.fromHTML($('#index_map').get(0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.