我正在使用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);
我怎样才能实现它?
答案 0 :(得分:6)
我们可以使用.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()