Search code examples
javascriptjqueryjspdf

jsPDF adjust the text-line spacing


In the jsPDF's documentation I can't find a method or a function to increase space between text-lines. I was wondering if somebody knowledgeable would nod mind sharing a bit of his/her knowledge :). Thanks much.


Solution

  • The output of API.text determines line height using lineHeightProportion:

            out(
                'BT\n/' +
                    activeFontKey + ' ' + activeFontSize + ' Tf\n' + // font face, style, size
                    (activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing
                    textColor +
                    '\n' + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' Td\n(' +
                    str +
                    ') Tj\nET'
            );
    

    changing the above respective line to

                    // (activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing
                    (activeFontSize * this.lineHeightProportion) + ' TL\n' + // line spacing
    

    and setting the variable:

    pdf = new jsPDF("portrait", "in", "letter");
    pdf.lineHeightProportion = 2;
    

    should do the trick.

    https://github.com/MrRio/jsPDF/pull/167