首页 > 解决方案 > 我需要在Angular的每个pdf页面中添加一些设计的页脚

问题描述

我正在使用Angular 10中的jspdfand将 html 转换为 pdf。但是并不起作用。如何为每个页面添加带有一些设计的页脚?html2canvasaddHtmlfromHtml

这是我的代码。

var data = document.getElementById('contentToConvert');
html2canvas(data).then((canvas) => {
  var imgWidth = 208;
  var pageHeight = 295;
  var imgHeight = (canvas.height * imgWidth) / canvas.width;
  var heightLeft = imgHeight;

  const contentDataURL = canvas.toDataURL('image/png');

  let pdf = new jspdf('p', 'mm', 'a4');
  var position = 0;
  pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
  heightLeft -= pageHeight;
  while (heightLeft >= 0) {
    position = heightLeft - imgHeight - 2;
    pdf.addPage();
    pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
    heightLeft -= pageHeight;
  }
  pdf.save('report.pdf');
});

标签: node.jsangularexpress

解决方案


推荐阅读