How to add page number in js.pdf

I am trying to add a page number to my pdf, but I cannot

here is my pdf output

enter image description here

here is my js code

$('#cmd').click(function () {
        var table = tableToJson($('#StudentInfoListTable').get(0))

        var doc = new jsPDF('p', 'pt', 'a4', true);

        doc.cellInitialize();
        doc.setFontSize(7);
        doc.text(200, 30, 'Leveraging ICT for Growth, Employment and Governance Project.');

        $.each(table, function (i, row){
                doc.setFontSize(7);

                if(i>1 && i%3==0)
                {

                    doc.addPage();
                    doc.cellInitialize();
                    doc.text(200, 30, 'Leveraging ICT for Growth, Employment and Governance Project.');
                }

                $.each(row, function (j, cell){
                        if(j=='name')
                        {
                            doc.cell(10, 50,100, 30, cell, i);
                        }
                        else if(j=='email')
                        {
                            doc.cell(10, 50,130, 30, cell, i);
                        }
                        else if(j=='track')
                        {
                            doc.cell(10, 50,40, 30, cell, i);
                        }
                        else if(j=='s.s.croll')
                        {
                            doc.cell(10, 50,51, 30, cell, i);
                        }
                        else if(j=='h.s.croll')
                        {
                            doc.cell(10, 50,51, 30, cell, i);
                        }
                        else 
                        {
                            doc.cell(10, 50,70, 30, cell, i);  // 2nd parameter=top margin,1st=left margin 3rd=row cell width 4th=Row height
                        }

                })


        })



        doc.save('sample-file.pdf');
    });

Is there a built-in function for page number in js.pdf?

+4
source share
1 answer

Try

doc.cellAddPage();

instead

doc.addPage();
0
source

Source: https://habr.com/ru/post/1524922/


All Articles