微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PDFMake动态表格式错误的表行

如何解决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 举报,一经查实,本站将立刻删除。