jsPDF Tutorial – Building Bar Code PDF in Javascript – Harshad Chopra

jsPDF Tutorial – Building Bar Code PDF in Javascript – Harshad Chopra

Hello friends in this post we will be making Bar Code PDF in Javascript with the help of jsPDF Library. Just Follow the steps which is given below and also the screenshots of the application is also shown below. And whole source code is also given and you can also extend this code and make some interactive app.

Source Code

index.html

<img id='itf' />
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>

script.js

JsBarcode("#itf", "12345678901237", {format: "itf"});

const img = document.querySelector('img#itf');

var doc = new jsPDF();
doc.setFontSize(40);
doc.text(30, 20, 'Hello world!');
doc.addImage(img.src, 'JPEG', 15, 40, 180, 160);
doc.save('my.pdf');

Leave a Reply

Close Menu