# html2canvas+jspdf纯前端实现html页面转pdf

1.用到的插件:html2canvas.js和jspdf.debug.js
2.demo:
$("#exportBtn“).on("click",function(){
       var element = $("#basicInfoContainer");

var w = element.outerWidth();

var h = element.outerHeight()+200;

var canvas = document.createElement("canvas");

canvas.width = w;

canvas.height = h;

var context = canvas.getContext("2d");

context.scale(5,5);

html2canvas(element,{

height:h,

onrendered:function(canvas){

var pageData = canvas.toDataURL("image/png",1.0);

var pdf = new jsPDF('','pt',[w*2,h*2]);

pdf.addIamge(pageData,‘png’,0,0,w,h);

pdf.save("pngName");
}
})
})

你可能感兴趣的:(# html2canvas+jspdf纯前端实现html页面转pdf)