1👍
✅
Wouldn’t setting a variable outside the document definition suffice?, I believe a piece of code will do the trick.
var columns = [];
var var1; // Defaults to undefined
var var2; // Defaults to undefined
var1 ="";
// If we have a value we add the column
if (var1 !== undefined) {
columns.push({ text: "var1" });
}
if (var2 !== undefined) {
columns.push({ text: "var2" });
}
// PDFMake document definition
var dd = {
content: [
{
alignment: 'justify',
columns: columns
},
]
...
}
Source:stackexchange.com