使用pdfkit时,我可以在同一段落中混合字体权重吗? [英] Can I mix font weights in the same paragraph when using pdfkit?
问题描述
我正试图在 中找到一种方法来使用粗体字体进行内联强调pdfkit
不幸的是,我找不到一种方法来改变字体而不强制换行(对于内联强调不好......)。 / p>
我尝试过这样的事情:
pdf.text('你好' ',LEFT,200).font(粗体).text('世界!');
但这将输出
您好
世界
<我也挖掘了源代码,但找不到任何防止这种情况的选择。
任何人都有任何想法或解决方法来解决这个问题吗?
编辑:
我现在所能提出的是一个丑陋的黑客,看起来像这样: / p>
pdf.text('Hello',LEFT,200).moveUp(1).font(bold).text('World !',{indent:pdf.widthOfString('Hello')});
这是有效但远非灵活和可维护。
基本上你需要用lineBreak设置选项:false,
pdf .text('Hello',LEFT,200,{
//这里是,
lineBreak:false
})。font(粗体).text('World!');
这将使Hello not break行,所以下一个World将打印在同一行。
我发现这个:
node_modules\pdfkit\js \ mixins\text.js,第130行
pdfkit版本:0.2.6
I'm trying to find a way to use bold font weights for inline emphasis in pdfkit
Unfortunately I cannot find a way to change the font without forcing a line break (bad for inline emphasis...).
I was trying something like:
pdf.text('Hello ', LEFT, 200).font(bold).text('World!');
but this will output
Hello
World
I also digged through the source but could not find any option to prevent this.
Anyone has any idea or workaround to tackle this problem?
EDIT:
All I could come up with by now is a ugly hack looking like this:
pdf.text('Hello ', LEFT, 200).moveUp(1).font(bold).text('World!', {indent: pdf.widthOfString('Hello ')});
which is working but far from flexible and maintainable.
Basically you need to set options with lineBreak : false,
pdf.text('Hello ', LEFT, 200, {
//here it is,
lineBreak : false
}).font(bold).text('World!');
This will make the Hello not break line, so the next World will print on the same line.
I found this in:
node_modules\pdfkit\js\mixins\text.js, line 130
pdfkit version: 0.2.6
这篇关于使用pdfkit时,我可以在同一段落中混合字体权重吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!