Search code examples
javascriptjspdfpdfmake

htmlToPdfmake set the alignment in the page footer


How can put page numbers in the center of the page footer in the following code

var val = htmlToPdfmake(html_all); 
var dd = {
    content: [val],
    styles:{'html-table':{alignment:'center'},'html-th':{color:'green'},'html-h5':{color:'blue', alignment:'center'}},
    pageOrientation: 'portrait', pageMargins: [40,60,40,30],
    footer: function(currentPage, pageCount) { return 'Page: ' + currentPage.toString() + ' of ' + pageCount; }
};
pdfMake.createPdf(dd).download();

Solution

  • Finally! I got the solution

    var val = htmlToPdfmake(html_all); 
    var dd = {
        content: [val],
        styles:{'html-table':{alignment:'center'},'html-th':{color:'green'},'html-h5':{color:'blue', alignment:'center'}},
        pageOrientation: 'portrait', pageMargins: [40,60,40,30],
        footer: function (currentPage, pageCount) {return {table: { widths: [ "*"],body: [[{text: 'Page: ' + currentPage.toString() + ' of ' + pageCount, alignment: 'center'}]]},};},
    };
    pdfMake.createPdf(dd).download();