简体   繁体   English

使用 .text() 方法的 jsPDF 中的字母间距

[英]letter spacing in jsPDF with .text() method

How do I specify letter spacing to text in jsPDF .text() method?如何在 jsPDF .text() 方法中为文本指定字母间距? This is the code I use now.这是我现在使用的代码。

var doc = new jsPDF('p', 'mm', [183, 203]);
doc.setFontSize(9);
doc.setFont("monospace");
doc.text(39, 38, 'hello world');
doc.output('dataurl');

Taken from jspdf.js , you can use lstext function to specify letter spacing. 取自jspdf.js ,可以使用lstext函数指定字母间距。

API.lstext = function (text, x, y, spacing) {
    for (var i = 0, len = text.length; i < len; i++, x += spacing) this.text(text[i], x, y);
};

Usage should be, 用法应该是

doc.lstext('Hello World', 39, 38, 5);

this will change the letter spacing of the entire pdf pdf.setCharSpace(5);这将改变整个 pdf pdf.setCharSpace(5) 的字母间距; 5 is the space that you give to the entire pdf, if you want to apply it only to a specific text it would be pdf.text('text', 30, 105, { charSpace: 5 }); 5 是您为整个 pdf 提供的空间,如果您只想将其应用于特定文本,则为 pdf.text('text', 30, 105, { charSpace: 5 });

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

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