const pages = document.querySelectorAll('.pdf-page');
const promises = Array.from(pages).map(page =>
html2canvas(page, {
scale: 2,
useCORS: true,
background: '#fff'
})
);
Promise.all(promises).then(canvases => {
const pdf = new jsPDF({
orientation: 'p',
unit: 'mm',
format: 'a4'
});
canvases.forEach((canvas, index) => {
const imgData = canvas.toDataURL('image/png');
const imgWidth = 210; // A4 页面宽度
const imgHeight = (canvas.height * imgWidth) / canvas.width;
if (index > 0) {
pdf.addPage();
}
pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
});
pdf.output('dataurlnewwindow'); // 在新窗口中打开 PDF
});
导出多个pdf并在页面中打开
于 2025-03-12 19:18:08 首次发布