Table does not break into pages with Dynamic creation
Hi; I'm creating my tables on the runtime with specific information. Unfortunately my table which should have been 8 pages long keeps being rendered under the same page into the oblivious.
How can I solve this?

include a sample doc-def-object
I'm fetching necessary data from remote server with Restangular and passing & parsing necessary fields: This is the main code that generates the PDF:
console.log( 'Bill Report PDF report');
var docDefinition = {
pageMargins: [40, 80, 40, 40],
//pageOrientation: 'landscape',
header: function(currentPage, pageCount) {
// you can apply any logic and return any valid pdfmake element
return { columns: [
{ image: 'data:image/png;base64,{image data} },
{ text: '{Some othe data} },
{ text: 'Page: '+currentPage+' of '+pageCount+'\n{data again}' }
],
// optional space between columns
columnGap: 5,
style: 'header'
};
},
content: [
{columns: [
[{text: 'DocTOK Statement\n', style: 'user_report'},
{style: 'user_table5',
table:{
headerRows: 1,
widths: [200, 'auto'],
body: [
[{ text: '{some data}', style: 'tableHeader2' }, { text: ''}],
[ 'Previous Balance:', {text: '{some data}', alignment: 'right'}],
[ 'Payment - 05/26 - Thank You!', {text: '{some data}', alignment: 'right' }],
[ 'Adjustments', {text: '$0.00', alignment: 'right' }],
[ 'Balance', {text: '$0.00', alignment: 'right' }],
[ 'New Charges:', {text: '{some data}', alignment: 'right' }],
]
},
layout: 'headerLineOnly'},
{text: '\n\n'},
{style: 'user_table5',
table:{
headerRows: 1,
widths: [200, 'auto'],
body: [
[{ text: 'Service Summary', style: 'tableHeader2' }, { text: ''}],
[ '{some data} Access', {text: '{some data}', alignment: 'right' }],
[ '{some data}', {text: '{some data}', alignment: 'right' }],
[{ text: 'Total', style: 'user_bold' }, { text: '' + '$46,829.00', style: 'user_bold', alignment: 'right' }],
]
},
layout: 'headerLineOnly'},
chargeFacilityTable(facilityList, [ 'name', 'charge']),],
{ width: 200,
table:{
headerRows: 1,
body: [
[{text: 'How to Contact Us:', style: 'user_bold2'}],
[{text: 'For questions on your account: {some data} or', style: 'user_not_bold2'}],
[{text: '{some data}', style: 'user_not_bold2'}],
[{text: '{some data}', style: 'user_not_bold2'}]
]
},
layout:{
hLineWidth: function(i, node) {
return (i === 0 || i === node.table.body.length) ? 1 : 0;
},
},
margin: [ -10, 10, -10, 0 ]
}
]
},
{style: 'user_table2',
table:{
headerRows: 1,
body: [
[{ text: 'Consultation Details', style: 'tableHeader2' }],
[''],
]
},
layout: 'headerLineOnly',
pageBreak: 'before'},
allFacilitiesCharges()
],
footer: {text: ''},
styles: {
header: {
fontSize: 10,
bold: false,
margin: [40, 20, 40, 10],
height: 200
},
subheader: {
fontSize: 16,
bold: true,
margin: [0, 10, 0, 5]
},
tableExample: {
margin: [0, 5, 0, 15]
},
tableHeader: {
bold: true,
fontSize: 8,
color: 'black',
alignment : 'center'
},
tableHeader2: {
bold: true,
fontSize: 14,
color: 'black'
},
facility_title: {
fontSize: 11,
color: 'black',
bold: true
},
user_bold: {
color: 'black',
bold: true
},
user_bold2: {
fontSize: 9,
color: 'black',
bold: true
},
user_not_bold2: {
fontSize: 9,
color: 'black',
bold: false
},
user_details: {
color: 'black',
bold: false,
fontSize: 25,
},
user_report: {
color: 'black',
bold: false,
fontSize: 24,
},
user_table:{
margin: [0, 5, 0, 15]
},
user_table2:{
bold: true,
fontSize: 14,
margin: [0, 5, 0, 15]
},
user_table3:{
bold: false,
fontSize: 6,
margin: [0, 5, 0, 15]
},
user_table4:{
bold: false,
fontSize: 7,
margin: [0, 5, 0, 15]
},
user_table5:{
fontSize: 12,
margin: [0, 5, 0, 15]
},
},
};
// open the PDF in a new window
pdfMake.createPdf(docDefinition).download('BillExport.pdf');
And this is the code helping me creating dynamic content:
// Dynamically create Table body [Facilty based detail total Charges]
function buildEachFacilityDetailTableBody(data, columns) {
var body = [];
var headers =[ {text: 'Time', style: 'tableHeader'}, {text: 'Referring', style: 'tableHeader'}, {text: 'Consulting', style: 'tableHeader'},
{text: 'Coord', style: 'tableHeader'}, {text: 'Min', style: 'tableHeader'}, {text: 'DICOM', style: 'tableHeader'},
{text: 'Charge', style: 'tableHeader'}];
body.push(headers);
data.forEach(function(row) {
var dataRow = [];
columns.forEach(function(column) {
dataRow.push(row[column] == null ? '' : row[column].toString());
})
body.push(dataRow);
});
return body;
};
// Dynamically create Table itself using body [Facility based detail table]
function facilityDetailTable(data, columns) {
return {
style: 'user_table3',
table: {
headerRows: 1,
widths: [80, 120, 120, 25, 25, 35, 40],
body: buildEachFacilityDetailTableBody(data, columns)
},
layout: 'noBorders'
};
};
I am having the same problem. seems to happen when there are margins present in the tables. did someone come up with a solution.?
Well, I found out how to reproduce the problem. If a page contains a static table and just under it a dynamic table, it won't break into pages especially if there are another 'pagebreak' commands inside the dynamic table.
How to add dynamic picture of PDFMaker
can you please fix this ?????