有没有一种方法可以减少DataTables导出的PDF中的单元格填充? PDFMake游乐场指出,导出表时可以编辑单元格填充,但是我还没有遇到任何这样做的代码示例。任何帮助表示赞赏。
答案 0 :(得分:1)
我也遇到了这个问题,这是我能想到的最简单的解决方案。
<script type="text/javascript">
$(document).ready(function () {
let $table = $('#whatever-your-table-is');
$table.DataTable({
buttons: [
'copy',
'excel',
'csv',
{
extend: 'pdf',
customize: function (doc) {
// Here's where you can control the cell padding
doc.styles.tableHeader.margin =
doc.styles.tableBodyOdd.margin =
doc.styles.tableBodyEven.margin = [10, 10, 10, 10];
},
pageSize : 'LETTER'
}
]
});
});
</script>
如果你找到一个未缩小的版本,这里有一个关于 DataTables 正在设置的样式的转储,所以我想我可以把 tableBodyOdd
和 tableBodyEven
弄乱并且它起作用了。
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
}
};
答案 1 :(得分:0)
在pdfmake中,可以通过为表https://pdfmake.github.io/docs/document-definition-object/tables/#own-table-layouts定义表布局来完成
例如:
const tableNode = {
style: 'tableStyle',
table: {
widths: ["*", "*", "*"],
body: []
},
layout: {
paddingLeft: (i, node) => 10,
paddingRight: (i, node) => 10,
paddingTop: (i, node) => 10,
paddingBottom: (i, node) => 10
}
}