(function(){
var form = $('.form');
$('#create_pdf').on('click',function(){
$('body').scrollTop(0);
createPDF();
});
//create pdf
function createPDF(){
getCanvas().then(function(canvas){
var img = canvas.toDataURL("image/jpeg"),
doc = new jsPDF({
unit:'px',
format:'a4'
});
doc.addImage(img, 'JPEG', 20, 20);
doc.save('techumber-html-to-pdf.pdf');
});
}
// create canvas object
function getCanvas(){
return html2canvas(form,{
imageTimeout:2000,
removeContainer:true
});
}
}());
What I have tried:
We want to convert a web page as it is to a PDF including all styles, Alignments. By using above code we are able to download a web page as a pdf in all browsers(Chrome, Firefox, IE-10,11) except IE9. we have used JSPDF v1.2.6 plugin.