MySQL Database Output (>500 rows) to be added to pdfmake

I suggest you add the lines after you create the payload, you can push the arrays to the table body.

[{"id":"e8cd8b56.0e0908","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3},{\"one\":1,\"two\":2,\"three\":3}]","payloadType":"json","x":190,"y":1320,"wires":[["8ba699c1.0f9858"]]},{"id":"8ba699c1.0f9858","type":"function","z":"bf9e1e33.030598","name":"Table format","func":"//datetime\nvar time = new Date().toLocaleString(\"de\");\n\nlet payload = {\n    pageOrientation: 'portrait',\n\tcontent: [\n\t   \t\t\t{\n\t\t\t    columnGap: 20,\n            columns: [\n               {\n\t\t\timage: msg.pellogo,\n\t\t    fit: [75, 75],\n\t\t\talignment: 'left'\n\t\t},\n\t\t\t\n\t\t\t{text: 'Daily Report _ Production', \n\t\t\t\tstyle: 'header',\n\t\talignment: 'center',\n\t\twidth: 300,\n\t\tmargin: [0,0,20,0]\n\t\t},\n\t\t\n\t\t{\n\t\t\timage: msg.stlogo,\n\t\t\tfit: [50,50],\n\t\t\talignment: 'right'\n\t\t},\n\t\t\n\t\t\t]\n\t\t\t},\n'\\n\\n',\n'Key Parameters for all Lines:',\n'\\n\\n',\n\t\t{\n\t\t\tstyle: 'DataTable',\n\t\t\talignment: 'center',\n\t\t\ttable: {\n\t\t\t    headerRows: 1,\n\t\t\t     fontSize: 7,\n\t\t\t\tbody: [\n\t\t\t\t\t[{text:'Line No', style: 'tableHeader'}, {text:'Plan Qty', style: 'tableHeader'}, {text:'Input Qty', style: 'tableHeader'}, {text:'Finshed Goods', style: 'tableHeader'} , {text:'Fall Off Rate', style: 'tableHeader'} , {text:'Productivity', style: 'tableHeader'}, {text:'Throughput Time', style: 'tableHeader'}, {text:'Total Tests', style: 'tableHeader'}, {text:'Pass Count', style: 'tableHeader'}, {text:'Fail Count', style: 'tableHeader'}, {text:'First Pass', style: 'tableHeader'}, {text:'R/W Pass', style: 'tableHeader'}, {text:'R/W Pending', style: 'tableHeader'}],\n\t\t\t\t]\n\t\t\t}\n\t\t},\n'\\n\\n',\n'\\n\\n',\n'Line 5 - Daily Production Trend - Last 7 Days',\n\t\t\t{\n\t\t\timage: msg.image2,\n\t\t\tfit: [400,225],\n\t\t\talignment: 'center'\n\t\t},\n'\\n\\n',\n'Line 5 - FOR Analysis',\n\t\t\t{\n\t\t\timage: msg.image3,\n\t\t\tfit: [200,200],\n\t\t\talignment: 'center'\n\t\t},\n\t\t\t\n    ],\n    \tstyles: {\n\t\theader: {\n\t\t\tfontSize: 18,\n\t\t\tbold: true,\n\t\t\tmargin: [0, 0, 0, 10]\n\t\t\t\n\t\t},\n\t\tsubheader: {\n\t\t\tfontSize: 16,\n\t\t\tbold: true,\n\t\t\tmargin: [0, 10, 0, 5]\n\t\t},\n\t\ttableExample: {\n\t\t\tmargin: [0, 5, 0, 15],\n\t\t\talignment: 'right'\n\t\t},\n\t\ttableHeader: {\n\t\t\tbold: true,\n\t\t\tfontSize: 10,\n\t\t\tcolor: 'black'\n\t\t},\n\t\t\tDataTable: {\n\t\t\tbold: false,\n\t\t\tfontSize: 10,\n\t\t\tcolor: 'black'\n\t\t},\n\t\t\tquote: {\n\t\t\titalics: true\n\t\t}\n    \t}\n};\nmsg.payload.forEach((obj,index) => {\n    let output =[`line${index+1}`];\n    Object.values(obj).forEach(val => output.push(val));\n    payload.content[4].table.body.push(output)\n})\nmsg.payload = payload;\nmsg.filename = '/home/pi/Pictures/pdf/Daily_report10072022.pdf'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":1340,"wires":[["e06e7e50.46ed48"]]},{"id":"e06e7e50.46ed48","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":1460,"wires":[]}]

I do not have your data, so you may have to edit the code to fit your data, if you do not require all properties from the msg.payload objects.

msg.payload.forEach((obj,index) => {
    let output =[`line${index+1}`];
    Object.values(obj).forEach(val => output.push(val));
    payload.content[4].table.body.push(output)
})
msg.payload = payload;

I rename the msg.payload to payload so as to not overwrite msg.payload

1 Like