Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

jsPDF Tutorial to Insert Hyperlinks in PDF Document Using link() & textWithLink() Methods in Browser

Posted on December 16, 2022

 

 

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

 

 

JavaScript
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.

 

 

 

Recent Posts

  • Android Java Project to Download Multiple Images From URL With Progressbar & Save it inside Gallery
  • Android Java Project to Capture Image From Camera & Save it inside Gallery
  • Android Java Project to Crop,Scale & Rotate Images Selected From Gallery and Save it inside SD Card
  • Android Kotlin Project to Load Image From URL into ImageView Widget
  • Android Java Project to Make HTTP Call to JSONPlaceholder API and Display Data in RecyclerView Using GSON & Volley Library
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme