PDFMake动态表格式错误的表行

问题描述

我正在使用PDFmake输出身份检查的PDF结果。支票将图像返回到应用程序-根据支票有2张或3张图像。图像将插入到动态表中。

我使用此循环准备图像:

    prepareImages(images) {
    if (images.length === 0) return [];
    const tableRows = [];
    for (let i = 0; i < images.length; i += 2) {
        const t = [];
        if (images[i]) t.push({ image: `data:image/png;base64,${images[i].image}`,width: 220,})
        if (images[i + 1]) t.push({ image: `data:image/png;base64,${images[i + 1].image}`,});
        tableRows.push(t);
    }

    return tableRows;
}

这是将数据插入表的位置(文档构建的其余部分的片段):

                {
                layout: 'lightHorizontalLines',// optional
                table: {
                    // headers are automatically repeated if the table spans over multiple pages
                    // you can declare how many rows should be treated as headers
                    headerRows: 1,widths: ['*','*'],body: [
                        [{
                                text: 'Images Captured',bold: true,margin: [5,80,0],fontSize: 15,},''
                        ],...rows,]
                },}

值得注意的是,“行”在文档构建函数函数局部作用域)的开头定义为变量。

当前,当用户完成检查时,如果检查返回两张图像,则说明文档创建正确。但是,如果检查返回了三张图像,则控制台中将显示错误的消息,指出表格行格式错误。请参阅下面的日志:

 Malformed table row  [
  {
    image: '$$pdfmake$$2',fillColor: undefined,_margin: null,_maxWidth: 220,_minWidth: 220,_width: 220,_height: 153.46938775510205,_alignment: undefined
  }
] in node  {
  layout: 'lightHorizontalLines',table: {
    headerRows: 1,widths: [ [Object],[Object] ],body: [ [Array],[Array],[Array] ]
  },_layout: {
    hlinewidth: [Function: hlinewidth],vlinewidth: [Function: vlinewidth],hLineColor: [Function: hLineColor],vLineColor: [Function: vLineColor],hLinestyle: [Function: hLinestyle],vLinestyle: [Function: vLinestyle],paddingLeft: [Function: paddingLeft],paddingRight: [Function: paddingRight],paddingTop: [Function: paddingTop],paddingBottom: [Function: paddingBottom],fillColor: [Function: fillColor],defaultBorder: true
  },_offsets: { total: 16,offsets: [ 0,16 ] }
}
(node:23) UnhandledPromiseRejectionWarning: Malformed table row,a cell is undefined.

有关如何更正此问题的任何建议?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)