is it possible repeat rows of table in pdf file with pdfmake.js
是否可以使用pdfmake.min.js重复以pdf格式生成的表中的行?
我正在创建一个PDF文件。在其中我需要根据我的api响应重复表的行,这是一个对象数组。
1 2 3 4 5 6 7 8 9 10 11 12 | var dd = {content: [ { table: { body: [ [ 'Col1', 'Col2', 'Col3'], [ '1', '2', '3'], [ '1', '2', '3'] ] } } ] }; |
这是使用pdfmake创建表的简单方法。
我的问题是我们可以使用其他替代方法(例如ng-repeat)来重复表行中的大数据吗?
我最好的方法是使用pdfmake来生成pdf。建议我如何重复表格行。
因此,我假设您正在创建pdf文件,如下所示:
其中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | var body = [], content = [], dd = { 'content' : content }; body.push(['col1', 'col2', 'col3']); var secondRow = []; // Push numbers 0, 1, 2 for (var i = 0; i < 3; i++) { secondRow.push("i is:" + i); } body.push(secondRow); // ... // Manipulate the 'body' any way you want. // ... // Lets push the manipulated body into the 'content' // which is already inside the 'dd'. content.push({ 'table' : { 'body' : body } }); // Now with all the manipulated data, create the pdf. pdfMake.createPdf(dd).open(); |
因此,重点是,当您完成所有设置并完成操作后,以所需的方式操作此js对象,请调用
如果将我的脚本粘贴到pdfmake-playground中,您会明白我的意思。