I know that there is 4 types of "setFontType" in jsPDF:
doc.setFontType("normal");
doc.setFontType("italic");
doc.setFontType("bold");
doc.setFontType("bolditalic");
i tried some things but i can't find it, so is there a underline setFontType in jsPDF?
I know this is late but i have a solution for this , you can do this in 2 ways :-
First you can use the inbuilt "line" option to draw a line below your text :-
doc.line(x-from,y-from,x-to,y-to);
Second you can display your text in html and then use the option to print html in your jspdf config for eg:-
<div id="disptext">
<div class="underText">Hello</div>
</div>
<br/>
<input type='button' value='download' id='downP' />
<style>
.underText { text-decoration: underline;}
</style>
<script>
$(document).ready(function() {
$('#downP').on('click', function() {
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML($('#disptext')[0], function() {
pdf.save('text.pdf');
});
});
});
</script>
In my case I'm using jsPDF inside of Nativescript, so I couldn't use 'addHTML.'
Adding a little to A Biswas first option I was able to get it to work for dynamic text size like this:
const textWidth = doc.getTextWidth(text);
doc.line(x, y, x + textWidth, y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With