I'm trying to make a simple mail-merge where recipients information is inserted on top of a template pdf.
The template is 1 page, but the result can be up to several hundred pages.
I have all recipient in array objects, but need to find a way to loop over that and create a unique page for each recipient.
I'm not sure if hummus-recipe is the right tool, so would greatly appreciate any input as to how to do this.
My demo looks like this
const HummusRecipe = require('hummus-recipe')
const recepients = [
{name: "John Doe", address: "My Streetname 23", zip: "23456", city: "My City"},
{name: "Jane Doe", address: "Another Streetname 56 ", zip: "54432", city: "Her City"}
//'.......'
]
const template = 'template.pdf';
const pdfDoc = new HummusRecipe(template, 'output.pdf');
function createPdf(){
pdfDoc
.editPage(1)
.text(recepients[0].name, 30, 60)
.text(recepients[0].address, 30, 75)
.text(recepients[0].zip + ' ' + recepients[0].city, 30, 90)
.endPage()
//. appendpage(template) - tried versions of this in loops etc., but can't get it to work.
.endPDF();
}
createPdf();
This obviously only create a single page with recipient[0]. I have tried all sorts of ways to loop over using .appendpage(template), but I can't append and then edit the same page.
Any advice how to move forward from here?