node.js - 我需要在Angular的每个pdf页面中添加一些设计的页脚
问题描述
我正在使用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');
});
解决方案
推荐阅读
- python - 在 Jupyter Notebook/Lab 中的 cell-return 上运行命令
- go - 一对多关系需要定义一个有效的外键错误
- excel - 用于数据 Web 抓取的 VBA
- python-3.x - 当不与 Django 的表单验证一起使用时,Django 的 models.TextField() 是否提供了很多安全性?
- javascript - 为什么我的 Auth0 API 调用在尝试删除用户时会出现 403 错误?
- javascript - 使用 extraData 在功能组件中重新渲染平面列表时遇到问题
- javascript - 如何将 React 开关的“已检查”值设置为 React Js 中的引用?
- java - FrameLayout中另一个下面的Android View不起作用
- javascript - 主题发出先前的值
- firebase-authentication - 使用 python API 使用 Firestore 身份验证重置密码