Add Fixed Header and footer to exported pdf file
Add Fixed Header and footer to exported pdf file
Hello
I need to add logo in header of my exported pdf and in footer i need to add page numbers and some parameters.
I googled so many things. But had no luck.
Can anyone guide me how to add header and footer in exported pdf?
Here is my code
$('#example_table').DataTable( {
"scrollX": true,
"scrollY": 380,
scrollCollapse: true,
"paging": true,
"ordering": true,
lengthMenu: [
[ 10, 25, 50, 2147483647 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
"pageLength": 2147483647,
scroller: true,
"serverSide": true,
"columnDefs": [ {
"targets": 0,
"orderable": false,
"searchable": false
} ],
"destroy":true,
"pagingType": "full_numbers",
"oLanguage": {
"sSearch": "<a class='btn searchBtn' id='searchBtn'><i class='fa fa-search'></i></a> "
},
dom: 'lBfrtip',
buttons: [
{
extend: 'excel',
exportOptions: {
columns: cols_export,
modifier: {
filter: 'applied', order: 'current'
}
}
},
{
extend: 'pdf',
customize: function (pdf) {
return "My header here....\n\n"+ pdf +"\n\nMy Footer here.....";
},
exportOptions: {
columns: cols_export
}
}
,'print'
],
"ajax":{
url : "include/display_list.php?keyword=" + 'civil_configuration_bim_table'+url_append,
type: "post",
error: function(data){
$(".employee-grid-error").html("");
$("#admin_list").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#employee-grid_processing").css("display","none");
},
},
deferRender: true
} );
});
Thanks in advance
This question has an accepted answers - jump to answer
Answers
Hi patelleena57,
it's really not so easy to customize the pdf output. Found that out recently when I needed to adjust some things myself. Below is the code I came up with. You need to focus on the customize section. Maybe you can use some parts and discover how to get your job done. Success.
Thanks a lot. It worked!
@F12Magic Can you help me How can i put header and footer in excel also?
Never done it before, but somewhere in the past I had made one with autofilters. So I adjusted that one to make a header and footer. You'll have to know a bit of working with nodes in javascript.
I made an example on Codepen
In the javascript window you'll find an explanation of default things you can put in the header and/or footer.
And for the ones that would like to see the code immediatly ...