angular - 如何以 7/8/9/10 的角度将表格转换为 pdf?
问题描述
我进行了广泛的搜索,发现了许多适用于 jsPDF 的解决方案。但是我找到的解决方案要么尝试手动添加文本行,这在我的场景中是不可能的;或者他们转换
解决方案
首先安装jspdf库
“npm 安装 jspdf --save”
jspdf@2.3.1 为我工作。
然后在组件中导入jspdf并创建导出功能
从'jspdf'导入{jsPDF};
generatePdf() {
var head = [['NAME', 'DATE', 'TIME']];
var table_data = [];
array.forEach((element: any) => {
var item = [element.Title, element.Date, element.Time];
table_data.push(item);
});
var doc = new jsPDF();
doc.setFontSize(18);
doc.text('Page', 11, 8);
doc.setFontSize(11);
doc.setTextColor(100);
(doc as any).autoTable({
head: head,
body: table_data,
theme: 'striped',
didDrawCell: data => {
// data
}
})
var data64 = doc.output('datauristring');
// create pdf file and download it
let a = document.createElement("a");
a.href = data64;
a.download = "myearning.pdf"
a.click();
}
推荐阅读
- javascript - 基于路径忽略库
- angular - 我们如何缩小像 app.min.js 这样的 Angular 应用程序并在其他应用程序中使用
- swift - 扩展 AppStorage 以兼容 Int32
- excel - 创建宏来制作数据透视表 + 直方图不起作用
- jupyter-notebook - 为什么我在使用“fine_tune”时不断收到进程条?
- android - 上下文如何向我们提供有关应用程序和活动的信息
- python - 使用 structlog 隐藏控制台
- swift - iOS Swift IBKS 信标错误:线程 1:致命错误:在展开可选值时意外发现 nil
- asp.net-core - Integrationtest IHost TestServer 不会关闭
- liquibase - liquibase中的行符号结束