如何在nodejs中的drawText pdf-lib方法中给单词之间留空格

问题描述 投票:0回答:1

我想在创建 PDF 文档时在文本中的单词之间留出空格,但我不知道如何做到这一点。

这是我的代码:

firstPage.drawText(`2 5 5 5 5 5 5 5`, {
  x: 274,
  y: 655,
  font: courierBoldFont,
  size: 15,
  color: rgb(0, 0.5, 1),
});

我想在添加字符串时在单词之间留有空格,但我不知道。我想要这样的结果

5   5   5   5   5  5  5
但字符串在 PDF 中显示得太近,像这样
55555555555555

node.js pdf
1个回答
1
投票

使用 courier 字体,字符间距应该完美,即使是等宽字体,只需添加额外的间距以适应您所做的。

你的代码应该看起来像这样间隔开,但是我怀疑你的字体定义

courierBoldFont,
可能是错误的

enter image description here

快递粗体的错误定义是不一样的大空格

enter image description here

我使用示例https://jsfiddle.net/jw4b5rku/4/进行更正 要测试快递行为,请尝试您的代码和版本

<script src="https://unpkg.com/[email protected]"></script>

<script src="https://unpkg.com/[email protected]"></script>

更换样品,看看使用快递时结果是否不同

© www.soinside.com 2019 - 2024. All rights reserved.