Welcome folks today in this blog post we will be adding hyperlinks in pdf document using link()
and textWithLink()
methods using jspdf library in browser using javascript. All the full source code of the application is shown below.
Get Started
In order to get started you need to include the jspdf
library cdn as shown below
1 2 3 4 5 6 7 8 9 |
<!doctype> <html> <head> <title>jsPDF Convert PDF to Base64 String</title> <script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script> </head> <body> </body> </html> |
Now we need to add the javascript code required for adding hyperlinks in pdf document as shown below
1 2 3 4 |
var doc = new jsPDF() doc.textWithLink('Click here', 10,10, { url: 'http://www.google.com' }); doc.save("output.pdf") |
As you can see we are using the textWithLink()
method to insert hyperlinks in pdf document. This method takes four arguments first is the actual hyperlink text and then we have the x and y coordinates and then lastly we put the actual url
to which the user will be redirected once he or she clicks the hyperlink text in pdf document.