是否可以用 pdfmake.js 在 pdf 文件中重复 table 行

is it possible repeat rows of table in pdf file with pdfmake.js

是否可以使用 pdfmake.min.js 重复在 pdf 中生成的 table 中的行? 我正在创建一个 PDF 文件。其中我需要根据我的 api 响应重复 table 行,这是一个对象数组。

var dd = {content: [
                    {   
                     table: {
                        body: [
                               [ 'Col1', 'Col2', 'Col3'],
                               [ '1', '2', '3'],
                               [ '1', '2', '3']
                              ]
                            }
                    }
                   ]
         };

这是使用 pdfmake 创建 table 的简单方法。 我的问题是我们可以使用任何替代方法(如 ng-repeat)在 table 的行中重复大数据吗? 我得到生成 pdf 的最佳方法是使用 pdfmake。建议我如何重复 table 行。

所以我假设您正在创建您的 pdf,如下所示: pdfMake.createPdf(dd).open();

其中 dd 变量基本上只是一个简单的 javascript 对象。您可以使用数组以任何方式扩展它,例如:

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 对象,当您完成设置并完成后,调用 createPdf

如果你将我的脚本粘贴到pdfmake-playground,你就会明白我的意思。