index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!DOCTYPE html> <html> <head> <title>JSPDF Page Numbers Example</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script> </head> <body> <button onclick="generatePDF()">Generate PDF</button> <script> function generatePDF() { // Create a new JSPDF instance let doc = new jsPDF() // Set the font size and style for the footer doc.setFontSize(10); doc.setFontStyle('italic'); doc.addPage() // Get the total number of pages in the document var totalPages = doc.internal.getNumberOfPages(); // Loop through each page and add the page number at the footer for (var i = 1; i <= totalPages; i++) { doc.setPage(i); doc.text(' ' + 'Page ' + i + ' of ' + totalPages, 10, doc.internal.pageSize.height - 10); } // Save the PDF document doc.save('example.pdf'); } </script> </body> </html> |