【问题标题】:PDFkit (Node): How to create paragraph indents?PDFkit(节点):如何创建段落缩进?
【发布时间】:2022-01-27 20:58:40
【问题描述】:

我正在尝试在 PDFkit 中创建段落缩进。 PDFkit 文档声明 indent 属性是“缩进每一段文本”。尝试这样做时,只有第一行有缩进。

const doc = new PDFDocument({ size: "A4" });
doc.pipe(fs.createWriteStream('output2.pdf'));
doc.addPage()
doc.text('fdgfdgfg fggfdgfdg fgfdg fdg dfgdfgdfg dfgfdg fgfgfdg fdgdfgdfg', { indent: 30 })
doc.end();

代码仅在段落的第一行提供缩进。如何缩进整个段落?

【问题讨论】:

  • 嗯,当然不是在 PDF 中,而是在生成框架中。

标签: javascript node-pdfkit


【解决方案1】:

如果你想要连续的段落,你需要doc.text and doc.moveDown

const doc = new PDFDocument({ size: "A4" });
doc.pipe(fs.createWriteStream('output2.pdf'));
doc.addPage()
doc.text('This is the start of paragraph 1', { indent: 30 });
doc.moveDown();
doc.text('This is the start of paragraph 2', { indent: 30 });
doc.moveDown();
doc.text('This is the start of paragraph 3', { indent: 30 });
doc.end();


【讨论】:

  • 谢谢。据我了解,每个 doc.text 都应该被视为一个段落,并根据相关问题 PDFKit 这样做,但不幸的是,我的情况并非如此。
【解决方案2】:

我从 PDFKit 迁移到 pdfmake(它基于 PDFKit),它为我的案例处理缩进的方式比 PDFkit 本身更好。 对于我的用例来说,它也更好,因为我使用来自我的 markdown 词法分析器的 JSON 输出,它可以很容易地转换为 pdfmake 的输入。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2011-01-28
  • 1970-01-01
  • 2022-08-13
  • 1970-01-01
  • 2020-04-06
  • 2021-10-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多