簡體   English   中英

如何在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);

但它返回虛線下方的文本,如下所示: 在此輸入圖像描述

我想得到: 在此輸入圖像描述

我怎樣才能實現它?

我們可以使用.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() 

收益: 在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM