简体   繁体   English

jsPDF调整文本行间距

[英]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.在 jsPDF 的文档中,我找不到增加文本行之间空间的方法或 function。 I was wondering if somebody knowledgeable would nod mind sharing a bit of his/her knowledge:).我想知道知识渊博的人是否会点头介意分享他/她的一些知识:)。 Thanks much.非常感谢。

You can also add parameters in the jsPDF constructor:您还可以在 jsPDF 构造函数中添加参数:

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

From jsPDF code (function jsPDF(orientation, unit, format, compressPdf)):来自 jsPDF 代码(函数 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: 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'
        );

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 https://github.com/MrRio/jsPDF/pull/167

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

working在职的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM