node.js 中 pdfkit-tables 中的垂直线

问题描述 投票:0回答:1

我有API可以在将值保存到数据库后生成pdf文件。我的客户需要生成此 pdf 文件,然后通过邮件发送。他给我发了这张 pdf 的照片。我重新创建了它,它看起来与那张图片相同,但由于缺少垂直线而很难阅读。我查看了文档,也尝试用谷歌搜索,但我什么也没找到。 这是我的 PDF 的样子:

如您所见,垂直线缺失,因此更难以阅读。

是否可以添加垂直线?

这是我的代码:

let doc = new PDFDocument({ margin: 30, size: "A4" });
      doc.pipe(
        fs.createWriteStream(`${problemName}_${creationDate}` + ".pdf")
      );
      const table = {
        title:
          "Zápis koordinátora " +
          koordinatorName +
          " zo dna " +
          creationDate +
          ".",
        divider: {
          header: { disabled: true },
          horizontal: { disabled: false, width: 1, opacity: 1 },
          padding: 5,
          columnSpacing: 10,
        },
        headers: [
          { width: 130, renderer: null },
          { width: 130, renderer: null },
          { width: 130, renderer: null },
          { width: 130, renderer: null },
        ],
        rows: [
          ["Nazov", problemName, "", ""],
          [
            "Nazov staveniska (Projekt)",
            constructionName,
            "Na vedomie komu",
            "mailing list 1",
          ],
          [
            "Vytvoril koordinator BOZP",
            koordinatorName,
            "Priorita",
            problemPriority,
          ],
          ["Datum zistenia", creationDate, "Datum odstranenia", ""],
          [
            "Zodpovedny za vyriesenie zistenia",
            "Janko Maly",
            "Celkovy pocet zisteni v dni",
            10,
          ],
          ["Miesto zistenia", discoveryPlace, "Zistenie císlo", 1],
          ["Popis", problemText],
          [
            "Navrh na udelenie sankcie",
            "50€",
            "Pre spolocnost",
            adressedFor,
          ],
        ],
      };

      doc.table(table, {
        prepareHeader: () => doc.font("Helvetica-Bold").fontSize(8),
        prepareRow: (row, indexColumn, indexRow, rectRow, rectCell) => {
          doc.font("Helvetica").fontSize(8);
          indexColumn === 0;
        },
      });
      doc.end();

我正在使用 pdfkit-table 包。

谢谢大家

node.js express pdfkit
1个回答
2
投票

根据定义,简单的 PDF 结构不是表格形式的,只有一个单元格(页面),并且一列可以细分为两行或多行,文本子列之间有空空格。

这就是为什么表格很难减去

因此,在一个区域中添加彩色行相当简单,就像表格一样,因此制作垂直细分则更加困难,但是该功能是在 2022 年 1 月添加的 https://github.com/natancabral/pdfkit-table/文件/7865078/document-5.pdf

例如,请参阅https://github.com/natancabral/pdfkit-table/issues/16#issuecomment-1012389097

根据待处理的拉取请求进行更新(尚未实现)以及下面@MoshFeu的评论。

为了允许标题有边框,我们还需要在标题上运行prepareRow。这对我有用。 https://github.com/natancabral/pdfkit-table/issues/16#issuecomment-1962831881

© www.soinside.com 2019 - 2024. All rights reserved.