Is there a underline setFontType in jsPDF?

Carlos Salles picture Carlos Salles · Oct 19, 2016 · Viewed 8.2k times · Source

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?

Answer

A Biswas picture A Biswas · Dec 19, 2016

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>