3
是否可以使用pdfmake創建內容表(TOC)?該庫將爲我生成PDF,但我不知道某個對象將在哪個頁面上呈現。當然,這取決於頁面大小,方向等。一些內容將流向下一頁。我無法預見如何提前計算一章的最終結果。如何使用pdfmake製作目錄?
考慮這個文檔定義:
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'
},
]
}
最容易笏測試是粘貼在操場此DD對象:http://pdfmake.org/playground.html
關於如何創建一個TOC任何想法?