So, our goal is to generate a PDF using the jsPDF library. In the PDF, we need to have a QR code. When the QR code is scanned it takes the user to a particular URL. Let us see how we can accomplish all this.
To do this, we will be using the QRCode.js library. It's maintained by davidshimjs.
Below is a github gist with everything you need to do:
Here is a link to a JS fiddle so that you can see it in action.
The plan is simple:
- We add the jsPDF CDN url.
- Create a new JS document.
- Use the "addImage" method to add the QR Code to the desired location in the document.
Let's look at some code:
Let us look at a working codepen.
We have developed a better way to generate PDFs. It's a simple drag and drop builder with QR Code support and many other things.