2016-04-12 24 views
3

pdfmake kullanarak bir içerik tablosu (TOC) yapmak mümkün mü? Kütüphane benim için PDF üretecek ancak belirli bir nesnenin hangi sayfada oluşturulacağı hakkında hiçbir fikrim yok. Elbette bu, sayfa boyutuna, yönelimine vb. Bağlıdır. Bazı içerikler bir sonraki sayfaya akacaktır. Bir bölüm bittiğinde önceden nasıl hesaplanacağımı göremiyorum. Bir TOK oluşturmak için nasıl http://pdfmake.org/playground.htmlpdfmake kullanarak içerik tablosu nasıl oluşturulur?

Herhangi bir fikir:

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' 
     }, 
    ] 
} 

testine en kolay wat oyun alanında bu dd nesneyi yapıştırmak için:

bu belge tanımı düşünün?

cevap

2

bu kadar yakın desteklenmeyen iken şimdi

var docDefinition = { 
    content: [ 
    { 
     toc: { 
     // id: 'mainToc' // optional 
     title: {text: 'INDEX', style: 'header'} 
     } 
    }, 
    { 
     text: 'This is a header', 
     style: 'header', 
     tocItem: true, // or tocItem: 'mainToc' if is used id in toc 
     // or tocItem: ['mainToc', 'subToc'] for multiple tocs 
    } 
    ] 
} 

Kaynak yapabilirsiniz: https://github.com/bpampuch/pdfmake#table-of-contents


bu son 0.1.28 sürümü henüz unutmayın. Ama bunun bir sonrakinde dahil edilecektir tahmin ve bu arada kolayca kaynaktan inşa edebilirsiniz:

git clone https://github.com/bpampuch/pdfmake.git 
cd pdfmake 
npm install # or: yarn 
git submodule update --init libs/FileSaver.js 
npm run build # or: yarn run build 

Kaynak: https://github.com/bpampuch/pdfmake#building-from-sources


Yukarıdaki ToC örneği sürece bu durumda işlevsel olduğunu teyit edebilir en az bir tane tocItem olduğu gibi. Sıfır tocItem s ve bir toc şu anda boş ToC tablosu nedeniyle bir istisna atar.

İlgili konular