HTML to PDF with images

时间:2019-04-08 12:52:19

标签: angular jspdf html-to-pdf

I am trying to convert html to pdf and after conversion it doesn't shows images that was in my web page.

I using jspdf.

var data = document.getElementById('reportSummary');
html2canvas(data).then(canvas => {
  // Few necessary setting options
  var imgWidth = 208;
  var imgHeight = canvas.height * imgWidth / canvas.width;
  var heightLeft = imgHeight;

  const contentDataURL = canvas.toDataURL('image/png')
  let pdf = new jspdf('p', 'mm', 'a4'); // A4 size page of PDF
  var position = 0;
  pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
  pdf.save('MYPdf.pdf'); // Generated PDF
});

0 个答案:

没有答案