jsPDF 调整文本行间距

7
在jsPDF的文档中,我找不到增加文本行之间距离的方法或函数。我想知道是否有谁知道并能分享一些他/她的知识:)。非常感谢。

1
你的意思是在text函数中使用字符串数组吗? - Joqus
3个回答

7
您可以在jsPDF构造函数中添加参数:
file = new jsPDF({orientation: "p", lineHeight: 1.5)})

从jsPDF代码中 (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

6
API.text的输出使用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'
        );

将上述各行更改为:
                // (activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing
                (activeFontSize * this.lineHeightProportion) + ' TL\n' + // line spacing

设置变量:

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

应该可以解决问题。

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


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

工作中


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接