【发布时间】:2016-04-12 15:41:14
【问题描述】:
是否可以使用 pdfmake 制作目录 (TOC)?该库将为我生成 PDF,但我不知道某个对象将在哪个页面上呈现。当然,这取决于页面大小、方向等。一些内容将流向下一页。我看不到如何提前计算一章的结尾。
考虑这个文档定义:
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 对象粘贴到 Playground 中:http://pdfmake.org/playground.html
关于如何创建目录的任何想法?
【问题讨论】:
标签: javascript pdfmake