first commit
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
// var html = template('tpl-user', { data: Array.from({ length: 44 }) });
|
||||
window.onload = () => {
|
||||
var html = template('tpl-after-sales', { data: Array.from({ length: 44 }) });
|
||||
document.getElementById("page").innerHTML = html;
|
||||
}
|
||||
|
||||
const exportPDF = () => {
|
||||
// 使用html2canvas捕获div内容
|
||||
html2canvas(document.getElementById("page"), {
|
||||
scale: 2, // 提高分辨率
|
||||
useCORS: true,
|
||||
allowTaint: true,
|
||||
logging: false,
|
||||
|
||||
}).then(canvas => {
|
||||
// 创建PDF
|
||||
const imgData = canvas.toDataURL('image/png', 1);
|
||||
|
||||
const link = document.createElement('a');
|
||||
link.download = `canvas-export.png`;
|
||||
link.href = imgData;
|
||||
link.click();
|
||||
return;
|
||||
|
||||
|
||||
|
||||
const pdf = new jspdf.jsPDF({
|
||||
orientation: 'portrait',
|
||||
unit: 'mm',
|
||||
// format: 'a4'
|
||||
format: [279.4, 194]
|
||||
});
|
||||
|
||||
// const imgWidth = pdf.internal.pageSize.getWidth();
|
||||
// const imgHeight = (canvas.height * imgWidth) / canvas.width;
|
||||
|
||||
// 添加图片到PDF
|
||||
// pdf.addImage(imgData, 'JPEG', 0, 0, 194, 279.4);
|
||||
pdf.addImage(imgData, 'JPEG', 0, 0, 194, 279.4);
|
||||
// console.log(imgWidth, imgHeight);
|
||||
// 保存PDF
|
||||
pdf.save(`1.pdf`);
|
||||
|
||||
// 恢复按钮状态
|
||||
// this.textContent = btnText;
|
||||
// this.disabled = false;
|
||||
}).catch(error => {
|
||||
console.error('导出PDF失败:', error);
|
||||
alert('导出PDF时出错,请重试。');
|
||||
|
||||
// 恢复按钮状态
|
||||
// this.textContent = btnText;
|
||||
// this.disabled = false;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user