利用html2canvas截图,html2canvas官方http://html2canvas.hertzen.com/
1.先导出
直接上代码
downloadPdf = async (refs,name)=>{
//导出字体样式失效问题
refs.style.fontVariant = 'small-caps!important';
//设置导出样式
this.setStyle(refs);
//refs为dom节点,name为图片名称
const canvas = await html2canvas(refs);
const width = canvas.width,height=canvas.height;
const imageData = canvas.toDataURL('image/png');
//三个参数,第一个方向,第二个单位,第三个尺寸格式
let doc;
if(width>height){
doc = new JsPDF('l','mm',[width*0.25,height*0.25]);
}else{
doc = new JsPDF('p','mm',[width*0.25,height*0.25]);
}
//第三个第四个分别控制 文字距离左边,文字距离上边的距离,后两个参数控制添加图片的尺寸,第八个压缩参数:‘NONE’,‘FAST’,‘MEDIUM’,and‘SLOW’
//参考手册
//往canvas里面添加图片
doc.addImage(imageData,'png',0,0,width*0.25,height*0.25,'','MEDIUM');
//保