Friday 22 April 2016

javascript - Export PDF from OpenLayers map with jsPDF


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


















And my Javascript :


$(document).ready(function () {

var doc = new jsPDF();

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

console.log(1);
return true;
}
};

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

var html=$("'#index_map").html();
console.log (html);
doc.fromHTML(html, 200, 200, {

'width': 500,
'elementHandlers': specialElementHandlers
});
doc.save('test.pdf');

});
});

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


enter image description here




Answer



Use:


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

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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...