JSPDF leaves white background when margin added

Viewed 431

I am using JsPDF to print dynamic resume data and i want to add margin when adding new page to pdf. Now when resume having a background color and i add margin while generating pdf it leaves the margined area as white and rest is OK.

var data = document.getElementById('box');

html2canvas(data,{scale: 2}).then(canvas => {

  var imgData = canvas.toDataURL('image/JPEG');
  var imgWidth = 210;
  var pageHeight = 295;
  var imgHeight = canvas.height * imgWidth / canvas.width;
  var heightLeft = imgHeight;

  var doc = new jsPDF('p', 'mm', "a4");
  var position = 1;

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

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

});
1 Answers

Use 'pt' instead of 'mm' as below, I hope it fixes,

var doc = new jsPDF('p', 'pt', "a4");
Related