Reputation: 1391
I have the following code which generates a datatable pdf upon pdf click. Inside the customize function, I have a footer code which is supposed to display page numbers.
$(document).ready(function () {
//SHOW EXSITING LINE ITEMS
var id = @Model.Order.Id;
table = $("#orders").DataTable({
dom: 'Bfrtip',
buttons: [
{
text: 'Download PDF',
extend: 'pdfHtml5',
className:'btn btn-primary',
orientation: 'landscape',
},
customize: function (doc) {
//set header
doc.content[0].text = "SALES ORDER";
doc.page
doc.pageMargins = [10, 10, 10, 10];
doc.defaultStyle.fontSize = 12;
doc.styles.tableHeader.fontSize = 14;
doc.styles.title.fontSize = 14;
// Set page title
doc.content[0].text = "SALES ORDER";
// Create a footer
doc.footer = (function (page, pages) {
return {
columns: [
'This is your left footer column',
{
// This is the right column
alignment: 'center',
text: ['page ', { text: page.toString() }, ' of ', { text: pages.toString() }]
}
],
margin: [10, 0]
}
});
}
}
],
I have added a footer code as seen above but I cannot seem to get the footer in my pdf. What am I doing wrong here?
Upvotes: 2
Views: 6177
Reputation: 85538
Basically you have not left space for the footer. You can use doc.pageMargins
to increase the available space at the bottom of the page, for example
doc.pageMargins = [10, 10, 45, 20]
You must take care of margins and size in the footer as well. A footer with some text to the left and page numbers to the right could look like this:
doc.footer = function(page, pages) {
return {
margin: [5, 0, 10, 0],
height: 30,
columns: [{
alignment: "left",
text: 'This is your left footer column',
}, {
alignment: "right",
text: [
{ text: page.toString(), italics: true },
" of ",
{ text: pages.toString(), italics: true }
]
}]
}
}
demo -> https://jsfiddle.net/np8em3sx/
Upvotes: 3