Home:ALL Converter>How to use pdfMake with dynamic data

How to use pdfMake with dynamic data

Ask Time:2019-11-20T03:24:55         Author:Omar

Json Formatter

I'm new to angular, I'm trying to use pdfMake, I can use it with static data but not able to achieve this with dynamic data, I would appreciate if you can help me achieve this it would be great, as I've searched all over the internet and couldn't quite get how I can achieve this. Thanks in advance.

employees.component.ts

getAllEmployees(){
    this.restService.GetAllEmployees().subscribe((res: any) => {
    this.employees = res.data.employees
    for(var i = 0; i< this.employees.length; i++) {
    this.array = this.employees[i]
    console.log(this.array)
    }
  })
}

generatePdf(){
  const documentDefinition = this.getDocumentDefinition();
  pdfMake.createPdf(documentDefinition).open();
}

getDocumentDefinition() {
  return {
    content: [
        {
        table: {
          headerRows: 4,
          widths: [ '*', 'auto', 100, '*' ],
          body: [
            [ 'Name', 'Second', 'Third', 'The last one' ],
            [ this.array.firstName_FL, 'Value 2', 'Value 3', 'Value 4' ],
          ]
        }
      }
    ]    
  };
}
ExportAsPDF(){
  this.generatePdf();
}

I've tried using this.array.firstName_FL however it comes up with last index only

Author:Omar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58941489/how-to-use-pdfmake-with-dynamic-data
yy