下载jspdf时会打印空白页而不是html标签

时间:2019-03-20 04:11:11

标签: typescript jspdf

这是我用来获取pdf的代码,但返回空白页而不是html标记

    this.loader = true;
    const filename = 'reports.pdf';
    const divWidth = document.getElementById('pdfexport').offsetWidth;
    const divHeight = document.getElementById('pdfexport').offsetHeight;
    // const divHeight = $('#pdfexport').height();
    // const divWidth = $('#pdfexport').width();
    console.log(divWidth, 'params', divHeight);
    html2canvas(document.getElementById('pdfexport'),
      {
        useCORS: true,
        width: divWidth,
        height: divHeight
       }
    ).then(canvas => {
      console.log(canvas, 'canvas');
      const pdf = new jspdf('p', 'mm', 'a4', true);
      const imgWidth = 210;
      const pageHeight = 295;
      const imgHeight = canvas.height * imgWidth / canvas.width;
      console.log(imgHeight, 'value');
      const Imgdata = canvas.toDataURL('image/jpeg, 0.7');
      console.log(Imgdata, 'Image');
      let position = 0;
      let heightLeft = imgHeight;
      const reports = Math.random().toString(35);
      pdf.addImage(canvas, 'PNG', 0, 0, imgWidth, imgHeight, undefined, 'FAST');
      console.log('varudhu');
      heightLeft -= pageHeight;
      while (heightLeft >= 0) {
        position = heightLeft - imgHeight;
        pdf.addPage();
        pdf.addImage(canvas, 'PNG', 0, position, imgWidth, imgHeight, undefined, 'FAST');
        heightLeft -= pageHeight;
      }
      this.loader = false;
      pdf.save(filename);
    });

这是我用来下载pdf的代码,我不知道为什么html标签不下载,而我却只得到一个空白页

0 个答案:

没有答案