I am using pdfkit node module to generate a pdf. My problem is that I want to insert a text on a dashed line. This is what I am doing:
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);
But it returns text just below the dashed line, like this:
And I want to get:
How can I achieve it?
We can use .moveTo
and split the lines into two and add the text in middle.
Try the code I've posted below, it is working for me:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With