I have already been to this thread Set Column width when exporting to pdf when using datatables net but it's almost a year old and didn't solve my problem. I want to adjust the column width of my columns when exporting the DataTable in pdf. I tried this, but nothing changed:
$('#table').dataTable({
"dom": '<"top"f>tiB',
paging: false,
fixedHeader: {headerOffset: 45},
buttons: [
{
extend: 'pdfHtml5',
exportOptions: {
columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
},
customize : function(doc) {
doc.styles['td:nth-child(8)'] = {
width: '1000px',
'max-width': '1000px'
}
},
text: 'Export: PDF',
orientation: 'landscape',
pageSize: 'A3',
}]
});
The pdfmake.js is included and I also tried width: 1000
or "width: 1000"
and things like that.
I have eight columns in my table and this code works fine for me:
$.extend( true, {}, buttonCommon, {
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A0',
customize: function (doc) {
doc.defaultStyle.fontSize = 8; //2, 3, 4,etc
doc.styles.tableHeader.fontSize = 10; //2, 3, 4, etc
doc.content[1].table.widths = [ '2%', '14%', '14%', '14%',
'14%', '14%', '14%', '14%'];
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With