I am fully aware that my problem most likely has something to do with me doing something wrong, but I can’t seem to figure it out. Here is my code:
for (let i = 0; i < formContentArray.length; i++) {
rowPosition = doc.y
columnPosition = doc.x
if (formContentArray[i].type == 'text' ) {
doc
.fill('#89cff0')
.fontSize(13)
.text(formContentArray[i].text, columnPosition, rowPosition, { align: "left" });
if (i == 0) {
doc.text('Done/Not Done', columnPosition, rowPosition, {align: 'right'})
}
}
else {
doc
.fill('#212121')
.fontSize(11)
.text(formContentArray[i].text,columnPosition, rowPosition, { align: "left" })
if (formContentArray[i].value) {
doc.text('Done', columnPosition, rowPosition, {align: 'right'})
}
else {
doc.text('Not Done', columnPosition, rowPosition, {align: 'right'} )
}
}
}
This works perfectly until the data fills out the page at which point PDFkit makes a new page. The next time it loops, it only does one loop, adds one line of text at the top of the 2nd page, and then adds a 3rd page. The loop then works perfectly on the 3rd page, finishing off the data. This obviously leaves the 2nd page though that is almost completely empty. I don’t understand? It has something to do with my rowPosition and columnPosition, I think. However, I need those in order to align text on the right-hand side with that on the left