如何在js.pdf中添加页码

时间:2014-02-02 11:12:42

标签: javascript pdf

我想在我的pdf文档中添加页码,但我不能

这是我的pdf输出

enter image description here

这是我的js代码

$('#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');
    });

在js.pdf中是否有内置的页码功能?

1 个答案:

答案 0 :(得分:0)

尝试

doc.cellAddPage();

而不是

doc.addPage();