如何更改数据表中的导出 PDF 字体大小? [英] How to change export PDF font size in datatables?

查看:33
本文介绍了如何更改数据表中的导出 PDF 字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,我有打印按钮和 pdf 按钮.我可以在打印页面时更改字体大小,但在导出 pdf 文件时无法更改字体大小.

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.

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

你能帮我吗?

推荐答案

如果看html5.js,它创建一个默认的对象文字 doc 保存默认设置:

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

您可以使用 customize 回调来更改这些默认设置:

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

<小时>

更改标题字体大小:

doc.styles.tableHeader.fontSize = 30    

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

更改对齐方式,将所有标题设置为中心,所有列都设置为页脚:

doc.defaultStyle.alignment = 'center'

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

这篇关于如何更改数据表中的导出 PDF 字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆