How to change export PDF font size in datatables?

后端 未结 1 1426
太阳男子
太阳男子 2020-12-15 07:31

I have a datatable and i have print button and pdf button. I can change font size when print page but i can\'t change font size while exporting pdf file.



        
相关标签:
1条回答
  • 2020-12-15 08:17

    If you look at the src of html5.js, it creates a default object literal doc holding default settings :

    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
        }
    };
    

    You can use the customize callback to change those default settings :

    {
       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 
       }  
    }, 
    

    Changing the header font size:

    doc.styles.tableHeader.fontSize = 30    
    

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

    Change alignment, set center to all headers, all columns all footers :

    doc.defaultStyle.alignment = 'center'
    

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

    0 讨论(0)
提交回复
热议问题