jsPDF调整文本行间距

jsPDF adjust the text-line spacing

本文关键字:文本 调整 jsPDF      更新时间:2023-09-26

在jsPDF的文档中,我找不到增加文本行间距的方法或函数。我想知道一个知识渊博的人是否会点头表示愿意分享他/她的一些知识:)。非常感谢。

您还可以在jsPDF构造函数中添加参数:

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

来自jsPDF代码(函数jsPDF(方向、单位、格式、压缩Pdf)):

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

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

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

工作