Welcome folks today in this blog post we will be looking on how we can add and delete pages inside pdf document in javascript using jspdf
library. All the full source code of the application is shown below.
Get Started
In order to get started you need to make an index.html
file and copy paste the following code
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 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Add Acroform Text Field in PDF Document</title> </head> <body> </body> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script> <script> var doc = new jsPDF() doc.addPage() doc.text("this is some text",10,10) console.log(doc.internal.getNumberOfPages()) doc.deletePage(2) doc.save("output.pdf") </script> </html> |
Here the method to add the page inside pdf document is addPage()
which adds an empty page inside pdf document and the method which is used to delete the page in pdf document is deletePage()
basically it takes the page number to delete. Here we are passing 2 so page number 2 in pdf document will be deleted successfully once you load the page.