最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jsPDF adjust the text-line spacing - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question edited Aug 29, 2013 at 23:39 Nactus asked Aug 29, 2013 at 23:04 NactusNactus 7123 gold badges14 silver badges35 bronze badges 1
  • 1 Do you mean when using a string array in the text function? – Joqus Commented Dec 2, 2013 at 20:34
Add a comment  | 

3 Answers 3

Reset to default 7

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

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

***pdf.text(text,10, 10,{lineHeightFactor: 1.5})***

working

发布评论

评论列表(0)

  1. 暂无评论