如何解决REACT- html2canvas和JS-PDF按钮单击下载模式元素
看看我的代码,我已经尝试了所有关于jsPDF和html2canvas以及React PDF的StackOverflow链接; 还尝试了自定义高度和宽度 但 我的页面模态高度为2353,宽度为900,高度太大,我知道但我自己无法管理。有人帮忙吗?
这是我的代码:
html2canvas(document.querySelector("#addCustomerData"),{
// height: document.querySelector("#addCustomerData").offsetHeight,// width: document.querySelector("#addCustomerData").offsetWidth + 200,allowTaint: true,}).then((canvas) => {
var imgData = canvas.toDataURL("image/png");
canvas.height = 2353;
canvas.width = 900;
// var imgWidth = 510;
var imgWidth = 210;
var pageHeight = 295;
// var pageHeight = 595;
console.log(canvas.height);
console.log(canvas.width);
// var imgHeight = (canvas.height * imgWidth) / canvas.width + 962;
var imgHeight = (canvas.height * imgWidth) / canvas.width + 350;
console.log(imgHeight);
var heightLeft = imgHeight;
var doc = new jsPDF("p","mm");
var position = 0;
doc.addImage(imgData,"PNG",position,imgWidth,imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData,imgHeight);
heightLeft -= pageHeight;
}
doc.save("test.pdf");
});
还记录整个值:
console.log(
"height: ",document.getElementById("addCustomerData").offsetHeight
);
console.log(
"width: ",document.getElementById("addCustomerData").offsetWidth
);
我告诉过的身高是:2353 宽度:900
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。