我在设置PDF导出文档的边距时遇到问题。我尝试了很多东西和设置,但没有希望。 有兴趣帮助和解决此问题的人可以查看以下链接: https://jsfiddle.net/ivans_software/hn2gcken/20/ http://live.datatables.net/poqoyezo/24/
$('#example').DataTable({
dom: 'Bfrtpi',
buttons: [
// 'colvis', // custom columns include JS https://cdn.datatables.net/buttons/1.0.1/js/buttons.colVis.min.js
// 'colvisRestore', // restore default columns include JS https://cdn.datatables.net/buttons/1.0.1/js/buttons.colVis.min.js
'pdf', { // default PDF and customized PDF
extend: 'pdfHtml5',
title: 'Random Persons', // report header/title
orientation: 'landscape',
pageSize: 'A4',
pageMargins: [ 0, 0, 0, 0 ], // try #1 setting margins
margin: [ 0, 0, 0, 0 ], // try #2 setting margins
text: '<u>E</u>xport Page (PDF)',
key: { // press E for export PDF
key: 'e',
altKey: false
}
, content: [{ style: 'fullWidth' }]
, styles: { // style for printing PDF body
fullWidth: { fontSize: 18, bold: true, alignment: 'right', margin: [0,0,0,0] }
},
download: 'download',
exportOptions: {
modifier: {
pageMargins: [ 0, 0, 0, 0 ], // try #3 setting margins
margin: [ 0, 0, 0, 0 ], // try #4 setting margins
alignment: 'center'
}
, body : {margin: [ 0, 0, 0, 0 ], pageMargins: [ 0, 0, 0, 0 ]} // try #5 setting margins
, columns: [0,1] //column id visible in PDF
, columnGap: 1 // optional space between columns
}
}],
columns: [
{
title: 'Person name',
defaultContent: '', // if no content set in field
data: 'name'
},
{
title: 'Person age',
type: 'num', // this would be a number field
data: 'age'
}
],
data: [
{name: 'John Doe', age: 25},
{name: 'Michael Jackson', age: 30},
{name: 'Tom Jones', age: 32},
{name: 'Monica Beluchi', age: 34}
]
});
第一个链接比第二个链接描述得更多,但重点是相同的......