Adding Footer to pdf using jsPDF

前端 未结 7 1484
南笙
南笙 2021-01-02 09:33

I am generating pdf from jsPDF api , I want to add footer to each page with page number .

How to achieve this . It is having option of adding footer from fromHTML p

7条回答
  •  执笔经年
    2021-01-02 10:21

    I know this post is old but I'm going to offer another solution. First define your total amount of pages. There's multiple ways to determine this so I won't go into that.

            var doc = new jsPDF('p', 'pt', 'letter');
            doc.page = 1; // use this as a counter.
            var totalPages = 10; // define total amount of pages
            // HEADER
            doc.setFontSize(20);//optional
            doc.setTextColor(40);//optional
            doc.setFontStyle('normal');//optional
            doc.text("Report", 50, 22);// set your margins
            // FOOTER
            var str = "Page " + doc.page  + " of " +  totalPages;
            doc.setFontSize(10);// optional
            doc.text(str, 50, doc.internal.pageSize.height - 10);//key is the interal pageSize function
    
    
            // Add Page content
            .....
    
    
            //Add new page and increase page count
            doc.addPage();
            doc.page ++;
            //Begin process all over again.
    

    This works well in a loop as you can set your page count by taking your array.length + 1 (as it's zero based).

提交回复
热议问题