使用 pdfmake 在 pdf 文件中显示数组元素

Show element of array in pdf file with pdfmake

在我的 angular 项目中,我到达了最后一页,其中包含一个包含从数据库中获取的数据的数组。 如何通过pdfmake将它们导入pdf?我想在第一列 interv.code 和第二列 interv.description

中显示 table
interv: AssociationInt[]
export class AssociationInt {
    interv: Interv
    price: number
    details: string
export class Interv {
    id: number
    code: string
    description: string

在 component.ts 文件中试试这个。

const content = [
{
          table: {
            headerRows: 1,
            widths: ['auto', 'auto'],
            body: [
              ['Code', 'Description'],
              ...this.interv.map(intervObj => 
                  [intervObj.interv.code, intervObj.interv.description]
              )
            ]
          }
        }
]

然后,使用 pdfMake 生成 PDF。

pdfMake.createPdf(content).open();