繁体   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