Hello all,
I’m trying to create an PDF with a dynamic created table in pdfmake.js.
The following code creates a static table and works properly:
var docDefinition = {
content: [
{
table: {
body: [
[ 'First', 'Second', 'Third', 'The last one' ],
[ 'Value 1', 'Value 2', 'Value 3', 'Value 4' ],
[ 'Val 1', 'Val 2', 'Val 3', 'Val 4' ]
]
}
}
]
};
I tried putting all data in an array and call it.
This almost works but does not give me the cell borders.
function html2Pdf(){
var arr = [[ 'First', 'Second', 'Third', 'The last one' ],[ 'Value 1', 'Value 2', 'Value 3', 'Value 4' ],[ { text: 'Bold value', bold: true }, 'Val 2', 'Val 3', 'Val 4' ]];
var docDefinition = {
content: [
{
table: {
body: [
arr
]
}
}
]
};
pdfMake.createPdf(docDefinition).open();
}
And here is another try with mapping because a for loop is not accepted.
It gives however the same result as the previous try:
function html2Pdf(){
var arr = [[ 'First', 'Second', 'Third', 'The last one' ],[ 'Value 1', 'Value 2', 'Value 3', 'Value 4' ],[ { text: 'Bold value', bold: true }, 'Val 2', 'Val 3', 'Val 4' ]];
var docDefinition = {
content: [
{
table: {
body: [
arr.map(function(item){
return item
})
]
}
}
]
};
pdfMake.createPdf(docDefinition).open();
}