我有一个数据表,我有打印按钮和 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'
},
你能帮助我吗?
最佳答案
如果你查看 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/
关于pdf - 如何更改数据表中的导出 PDF 字体大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33998231/