2015-11-30 29 views
8

我有一個數據表,我有打印按鈕和pdf按鈕。 我可以在打印頁面時更改字體大小,但在導出PDF文件時我無法更改字體大小。如何更改數據表中導出PDF字體大小?

{ 
     extend: 'pdfHtml5', 
     text: 'Save PDF', 
     exportOptions: { 
      modifier: { 
       page: 'current' 
      } 
     }, 
     header: true, 
     title: 'My Table Title', 
     orientation: 'landscape' 
    }, 
    { 
     extend: 'print', 
     text: 'Print', 
      customize: function (win) { 
       $(win.document.body) 
        .css('font-size', '15pt') 


       $(win.document.body).find('table') 
        .addClass('compact') 
        .css('font-size', '8pt'); 
      }, 
      header: false, 
      title: '', 
      orientation: 'landscape' 
    }, 

你能幫助我嗎?

回答

14

如果你看看html5.js的SRC,它會創建一個默認的對象字面doc保持默認設置:

var doc = { 
    pageSize: config.pageSize, 
    pageOrientation: config.orientation, 
    content: [ 
     { 
      table: { 
       headerRows: 1, 
       body: rows 
      }, 
      layout: 'noBorders' 
     } 
    ], 
    styles: { 
     tableHeader: { 
      bold: true, 
      fontSize: 11, 
      color: 'white', 
      fillColor: '#2d4154', 
      alignment: 'center' 
     }, 
     tableBodyEven: {}, 
     tableBodyOdd: { 
      fillColor: '#f3f3f3' 
     }, 
     tableFooter: { 
      bold: true, 
      fontSize: 11, 
      color: 'white', 
      fillColor: '#2d4154' 
     }, 
     title: { 
      alignment: 'center', 
      fontSize: 15 
     }, 
     message: {} 
    }, 
    defaultStyle: { 
     fontSize: 10 
    } 
}; 

可以使用customize回調來更改這些默認設置:

{ 
    extend: 'pdfHtml5', 
    text: 'Save PDF', 
    exportOptions: { 
     modifier: { 
     page: 'current' 
     } 
    }, 
    header: true, 
    title: 'My Table Title', 
    orientation: 'landscape', 
    customize: function(doc) { 
     doc.defaultStyle.fontSize = 16; //<-- set fontsize to 16 instead of 10 
    } 
}, 

更改標題字體大小:

doc.styles.tableHeader.fontSize = 30  

https://jsfiddle.net/2nwqa2jk/12/

變化調整,設置中心所有標題,所有列的所有頁腳:

doc.defaultStyle.alignment = 'center' 

https://jsfiddle.net/2nwqa2jk/13/

+0

感謝,得到了它;) – mrcherie

+1

我的桌子左對齊我n導出pdf。如何將其對齊到中心? –

+0

這不適合我請幫助。 –