7

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 オブジェクトをプレイグラウンドに貼り付けることです: http://pdfmake.org/playground.html

TOC の作成方法に関するアイデアはありますか?

4

1 に答える 1