如何在 node.js pdf 工具包中的一行上写一个文本?
How to write a text on a line in node.js pdf kit?
我正在使用 pdfkit 节点模块生成 pdf。我的问题是我想在虚线上插入文本。这就是我正在做的:
doc.moveDown(2)
.moveTo(x+leftMargin, doc.y)
.lineTo(doc.x, doc.y)
.lineWidth(0.5)
.dash(3,{space:3})
.fillAndStroke(defBlackColor)
.fill(defBlackColor)
.fontSize(defFontSize)
.text('Layover:'+' '+ obj.layover,x + leftMargin + xincr/2,doc.y);
但是它 returns 文本就在虚线下面,像这样:
我想得到:
如何实现?
我们可以使用 .moveTo
将行分成两行并在中间添加文本。
试试我在下面发布的代码,它对我有用:
doc.moveTo(200, 200) // this is your starting position of the line, from the left side of the screen 200 and from top 200
.lineTo(400, 200) // this is the end point the line
.dash(5, { space: 10 }) // here we are formatting it to dash
.text("text goes here", 410, 195) // the text and the position where the it should come
doc.moveTo(500, 200) //again we are giving a starting position for the text
.lineTo(800, 200) //end point
.dash(5, {space: 10}) //adding dash
.stroke()
returns:
我正在使用 pdfkit 节点模块生成 pdf。我的问题是我想在虚线上插入文本。这就是我正在做的:
doc.moveDown(2)
.moveTo(x+leftMargin, doc.y)
.lineTo(doc.x, doc.y)
.lineWidth(0.5)
.dash(3,{space:3})
.fillAndStroke(defBlackColor)
.fill(defBlackColor)
.fontSize(defFontSize)
.text('Layover:'+' '+ obj.layover,x + leftMargin + xincr/2,doc.y);
但是它 returns 文本就在虚线下面,像这样:
我想得到:
如何实现?
我们可以使用 .moveTo
将行分成两行并在中间添加文本。
试试我在下面发布的代码,它对我有用:
doc.moveTo(200, 200) // this is your starting position of the line, from the left side of the screen 200 and from top 200
.lineTo(400, 200) // this is the end point the line
.dash(5, { space: 10 }) // here we are formatting it to dash
.text("text goes here", 410, 195) // the text and the position where the it should come
doc.moveTo(500, 200) //again we are giving a starting position for the text
.lineTo(800, 200) //end point
.dash(5, {space: 10}) //adding dash
.stroke()
returns: