使用jspdf在单独的页面上将两个div保存为pdf

时间:2020-10-20 21:37:53

标签: html pdf export jspdf html2canvas

我有这段代码可将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> 

0 个答案:

没有答案
相关问题