页面之间的空白jspdf多页

时间:2019-04-27 12:03:30

标签: angular jspdf

我在Angular 7中使用了jsPDF。这是我的方法:

 generatePDF(){
    html2canvas(document.getElementById('print')).then(function(canvas) {

      var imgData = canvas.toDataURL('image/JPEG');

      /*
      Here are the numbers (paper width and height) that I found to work. 
      It still creates a little overlap part between the pages, but good enough for me.
      if you can find an official number from jsPDF, use them.
      */
      var imgWidth = 210; 
      var pageHeight = 295;  
      var imgHeight = canvas.height * imgWidth / canvas.width;
      var heightLeft = imgHeight;

      var doc = new jsPDF('p', 'mm');
      var position = 0;

      doc.addImage(imgData, 'JPEG', 0, position, imgWidth, imgHeight);
      heightLeft -= pageHeight;

      while (heightLeft >= 0) {
        position = heightLeft - imgHeight;
        doc.addPage();
        doc.addImage(imgData, 'JPEG', 0, position, imgWidth, imgHeight);
        heightLeft -= pageHeight;
      }


      doc.save( 'file.pdf');
    });
  }

但是它在页面之间放置了空白黑线。 任何想法? enter image description here

0 个答案:

没有答案