Reputation: 169
I'm using PDFMake to generate a bunch of details of each person I ticked in my table.
Here is what it looks like:
In every ticked I make I should generate their details in separate coupon bond (pageBreak) in a PDF using PDFMake along with their QR Code. I successfully prints that in my console:
Here's my code for that:
var docDefinition;
for (var vin = 0; vin < this.selected.length; vin++) {
var nestedArr = new Array(this.selected);
var s = nestedArr[0][vin].LAST_M + "\n" + nestedArr[0][vin].MEMB_N;
console.log(s);
docDefinition = {
pageSize: "A6",
pageMargins: [0, 0, 0, 0],
content: { text: s }
};
}
pdfMake.createPdf(docDefinition).print();
},
But when it comes to generation of PDF with their details, it only generates the last ticked person and not all the persons I ticked. As you can see in the image below:
I guess the problem is on docDefinition because it creates an instance every time I generate a PDF and only gets the last person I ticked.
What can I do to solve this problem?
Upvotes: 0
Views: 225
Reputation: 169
This trick worked for me. Grabbed the code from this question also from GitHub
var docDefinition;
var text = [];
for (var vin = 0; vin < this.selected.length; vin++) {
var nestedArr = new Array(this.selected);
var s = nestedArr[0][vin].LAST_M + "\n" + nestedArr[0][vin].MEMB_N;
text.push(s);
}
var docDefinition = {
content: text.map(function(item) {
return { text: item, pageBreak: "after" };
})
};
pdfMake.createPdf(docDefinition).print();
Upvotes: 0
Reputation: 22393
Your docDefinition
is rewritten every time in for loop, so it only takes last value. You can change to:
var docDefinition;
var text = []
for (var vin = 0; vin < this.selected.length; vin++) {
var nestedArr = new Array(this.selected);
var s = nestedArr[0][vin].LAST_M + "\n" + nestedArr[0][vin].MEMB_N;
text.push(s)
}
docDefinition = {
pageSize: "A6",
pageMargins: [0, 0, 0, 0],
content: { text: text.join("\n") }
};
pdfMake.createPdf(docDefinition).print();
Upvotes: 1