我有这段代码可将ID为invoice
的div导出为pdf(按下按钮时)。
exportAsPDF(div_id)
{
var doc = new jspdf();
var content = document.getElementById('invoice')
html2canvas(content)
.then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jspdf({
orientation: 'portrait',
});
const imgProps= pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'pdf', 0, 0, pdfWidth, pdfHeight);
pdf.save('download.pdf');
});
}
但是,我希望invoice
显示在第一页上,details
显示在第二页(同一文档)上。
我该如何实现?我看过很多文档,但似乎看不到正确的解释。
例如我的HTML是:
<div id='invoice'>
<span> Some text </span>
</div>
<div id='details'>
<span> Some other text </span>
</div>