HTML table in pdfkit (Expressjs-Nodejs)

后端 未结 3 778
长发绾君心
长发绾君心 2020-12-30 06:17

I am using pdfkit to generate pdf file and i want to send this pdf file to browser.
My following code is working fine and i am getting one pdf with text.

3条回答
  •  轮回少年
    2020-12-30 06:49

    this worked for me:

    artikelList.map(artikel => {
      let yPos = doc.y;
      doc
        .fontSize(8)
        .text(artikel.titel, (x = 50), (y = yPos))
        .text(artikel.menge, (x = 200), (y = yPos))
        .text(`${artikel.spOhne.toFixed(2)}€`, (x = 250), (y = yPos))
        .text(`${(artikel.USt / 100).toFixed(2)}%`, (x = 350), (y = yPos))
        .text(
          `${(artikel.spOhne * (1 + artikel.USt / 100)).toFixed(2)}€`,
          (x = 400),
          (y = yPos)
        )
        .text(
          `${(artikel.menge * artikel.spOhne * (1 + artikel.USt / 100)).toFixed(
            2
          )}€`,
          (x = 475),
          (y = yPos),
          { align: 'right' }
        );
    });
    

    literally just fixing the y-position and then moving through the x-positions. I guess with adding rec and stroke it would be pretty straight forward to draw the lines around it.

    Produces something that looks like this

提交回复
热议问题