javascript - 使用jspdf将内容导出为pdf angular
问题描述
我正在尝试使用 jspdf 创建一个 pdf。但是我遇到了错误cannot create property 'header' on string 'Details'
。我经历了这个问题如何修复:无法在字符串上创建属性“标题”但找不到解决方案。请帮助。提前致谢。这是我的转换功能
convert() {
var doc = new jsPDF();
var col = ["Details", "Values"];
var rows = [];
/* The following array of object as response from the API req */
var itemNew = [
{ id: 'Case Number', name: '101111111' },
{ id: 'Patient Name', name: 'UAT DR' },
{ id: 'Hospital Name', name: 'Dr Abcd' }
];
itemNew.forEach(element => {
var temp = [element.id, element.name];
rows.push(temp);
});
doc.autoTable(col, rows);
doc.save('Test.pdf');
}
StackBLitz:https ://stackblitz.com/edit/angular-jspdf-xgoetc?file=app/app.component.ts
解决方案
问题出autoTable()
在您指定head
和的函数中body
。
var col = [["Details", "Values"]];
改变autoTable()
喜欢
doc.autoTable({
head: col,
body: rows
});
更新片段:
convert() {
var doc = new jsPDF();
var col = [["Details", "Values"]];
var rows = [];
/* The following array of object as response from the API req */
var itemNew = [
{ id: 'Case Number', name: '101111111' },
{ id: 'Patient Name', name: 'UAT DR' },
{ id: 'Hospital Name', name: 'Dr Abcd' }
];
itemNew.forEach(element => {
var temp = [element.id, element.name];
rows.push(temp);
});
//doc.autoTable(col, rows);
doc.autoTable({
head: col,
body: rows
});
doc.save('Test.pdf');
}
PDF 预览(Test.pdf):
有关更多信息,请参阅jsPDF-AutoTable 文档。
推荐阅读
- python - 如何在 Win10 的 Jupyter notebook 中从 Python 单元格创建 csv 文件?
- php - 使php循环回显内容一次
- python - 为用户添加角色 discord.py
- rest - SharePoint 2019 应用程序的后端
- botframework - 如何在不使用 node.js 框架的情况下实现 MS Teams 机器人?
- python - 尝试通过 pip 将 Google Maps 模块安装到 python 语法错误上
- javascript - 对象[] | object[] 类型缺少 'find(),foreach()' 的调用签名
- android - 在 ARCore Android 中使用画中画模式
- typescript - 以编程方式从 API 数据创建 Typescript 声明
- typescript - 如何使Atom黄瓜步跳包在windows上工作?