我正在使用Angular 10中的jspdf
and将 html 转换为 pdf。但是并不起作用。如何为每个页面添加带有一些设计的页脚?html2canvas
addHtml
fromHtml
这是我的代码。
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');
});