Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

You can also add parameters in the jsPDF constructor:

file = new jsPDF({orientation: "p", lineHeight: 1.5)})

From jsPDF code (function jsPDF(orientation, unit, format, compressPdf)):

var options = {};

if (typeof orientation === 'object') {
    options = orientation;

    orientation = options.orientation;
    unit = options.unit || unit;
    format = options.format || format;
    compressPdf = options.compress || options.compressPdf || compressPdf;
}

// Default options
unit = unit || 'mm';
format = format || 'a4';
orientation = ('' + (orientation || 'P')).toLowerCase();

var format_as_string = ('' + format).toLowerCase(),
    compress = !!compressPdf && typeof Uint8Array === 'function',
    textColor = options.textColor || '0 g',
    drawColor = options.drawColor || '0 G',
    activeFontSize = options.fontSize || 16,
    lineHeightProportion = options.lineHeight || 1.15,
    lineWidth = options.lineWidth || 0.200025; // 2mm
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top