1、就是截图里面有一个table,table字段太多,导致有滚动条
2、所以截图的时候,后面隐藏的部分,没有截取到
3、相关代码
getPdf(pdfTitle){
let that = this;
html2canvas(document.querySelector("#pdfDom"),{
//跨域
allowTaint:false,
useCORS:true,
}).then(canvas => {
let contentWidth = canvas.width;
let contentHeight = canvas.height;
let pageHeight = (contentWidth / 592.28) * 841.89;
let leftHeight = contentHeight;
let position = 0;
let imgWidth = 595.28;
let imgHeight = (592.28 / contentWidth) * contentHeight;
var imgData = canvas.toDataURL("image/jpeg",1.0)
var PDF = new JsPDF("", "pt", "a4");
//单页
if (leftHeight < pageHeight) {
// PDF.addImage(pageData, "JPEG", 0, 0, imgWidth, imgHeight);
PDF.addImage(imgData, "JPEG", 0, 0, imgWidth, imgHeight);
} else {
//多页
while (leftHeight > 0) {
PDF.addImage(imgData, "JPEG", 0, position, imgWidth, imgHeight);
leftHeight -= pageHeight;
position -= 841.89;
//排除空白页
if (leftHeight > 0) {
PDF.addPage();
}
}
}
PDF.save(pdfTitle + ".pdf");
});
that.printAssetsView = false;
},
4、网上看了,都说是body的宽度问题,canvas的width超过了body的width
5、就是想要,滚动条后面隐藏的部分,也能截取到