I am using jQuery Data Table to export table as pdf.Now the pdf all the text are left aligned.How can I change it to right aligned?I need to add custom css to the exported pdf.
Here is my code
$('#reporTable').DataTable({
"paging" : false,
"ordering": false,
"info" : false,
"searching" : false,
dom: 'T<"clear">lfrtip',
tableTools: {
"sSwfPath": "/javascripts/js/dataTables/tools/swf/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends": "pdf",
"sTitle": filename,
"sPdfOrientation": "landscape",
"sPdfMessage": out_name+":" + msg
},
],
}
});
Use the customize
callback. It is not so well documented, see this answer for some references, or you could simply try to investigate the passed doc
literal yourself. Basically
customize: function(doc) {
doc.defaultStyle.alignment = 'right';
doc.styles.tableHeader.alignment = 'right';
}
will end up in a PDF with right aligned headers and cell content. A sample could be
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [{
extend: 'pdfHtml5',
customize: function(doc) {
doc.defaultStyle.alignment = 'right';
doc.styles.tableHeader.alignment = 'right';
}
}]
})
demo -> https://jsfiddle.net/yzdtLz36/
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