Create Next page
Closed this issue · 8 comments
Hi, I'm using this module and have same questions, I don't know create more one page. How I do?
Hi, have you tried this?
table.setNewPageFn(function (table, row) { table.pdf.addPage(); });
I tried that way but it happens "Cannot read property 'height' of null" in voilab-table.js:105:69
That's strange. Have you also tried to add a page before starting the whole process? Something like
pdf.addPage();
table.addBody(/*...*/);
because a page needs to be created so the first lines of the table can be drawn on it.
This is my code
module.exports = {
create: function (lista) {
var pdf = new PdfDocument({
autoFirstPage: false
}),
table = new PdfTable(pdf, {
bottomMargin: 5,
height: 20
});
table
.addPlugin(new (require('voilab-pdf-table/plugins/fitcolumn'))({
column: 'nome'
}))
.setColumnsDefaults({
headerBorder: 'B',
align: 'right',
})
.addColumns([
{
id: 'nome',
header: 'NOME',
align: 'left',
width: 30,
height: 18
},
{
id: 'email',
header: 'EMAIL',
align: 'right',
width: 200,
height: 18,
renderer: function (tb, data) {
return data.email;
}
}
])
.onPageAdded(function (tb) {
tb.addHeader();
});
table.addBody(lista);
table.setNewPageFn(function (table, row) {
table.pdf.addPage();
});
return pdf;
}
ok, so check my previous answer. You need to add a page before calling table.addBody
. I need to refactor this part, but for now, this is how to do it.
Ok, but if I add a page before table.addBody the function to generate others pages not work
and if you try to call setNewPageFn
before addBody
?
Thks