Is it possible to make a table of content (TOC) using pdfmake? The library will generate the PDF for me but I have no idea on which page a certain object will be rendered. Of course this depends on page size, orientation, etc. Some content will flow to a next page. I can't see how to calculate in advance where a chapter ends up.
Consider this document definition:
var dd = {
footer: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; },
content: [
'Table of contents\n\n',
'Chapter 1 ....... ?',
'Chapter 2 ....... ?',
'Chapter 3 ....... ?',
'Chapter 4 ....... ?',
{
text: '',
pageBreak: 'after'
},
{
text: 'Chapter 1: is on page 2',
pageBreak: 'after'
},
{
stack: [
'Chapter 2: is on page 3\n',
'A LOT OF ROWS 2\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n',
'A LOT OF ROWS 2\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n',
'A LOT OF ROWS 2\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n',
'A LOT OF ROWS 2\nWill go to the next page if this line contains a lot of text. Will go to the next page if this line contains a lot of text. Will go to the next page if this line contains a lot of text.'
],
pageBreak: 'after'
},
{
text: 'chapter 3: is on page 5',
pageBreak: 'after'
},
{
text: 'chapter 4: is on page 6'
},
]
}
The most easy wat to test is to paste this dd object in the playground: http://pdfmake.org/playground.html
Any ideas on how to create a TOC?