Adding Footer to pdf using jsPDF

前端 未结 7 1596
南笙
南笙 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:15

    It's work for me:

    I just put coordenates for A4 Paper;

    Just add the for before doc.save() like this;

    // Create a document

    var doc = new jsPDF('p','mm','a4');
    
    // Some stuff
    doc.text("Some text", 74, 150);
    doc.addPage();
    doc.text("Some text", 74, 150);
    doc.addPage();
    doc.text("Some text", 74, 150);
    doc.addPage();
    doc.text("Some text", 74, 150);
    doc.addPage();
    doc.text("Last page", 74, 150);
    
    // PAGE NUMBERING
    // Add Page number at bottom-right
    // Get the number of pages
    const pageCount = doc.internal.getNumberOfPages();
    
    // For each page, print the page number and the total pages
    for(var i = 1; i <= pageCount; i++) {
         // Go to page i
        doc.setPage(i);
         //Print Page 1 of 4 for example
        doc.text('Page ' + String(i) + ' of ' + String(pageCount),210-20,297-30,null,null,"right");
    }
    
    // Save the doc
    doc.save('test.pdf');
    

提交回复
热议问题