Home > Enterprise >  Vertical lines in pdfkit-tables in node.js
Vertical lines in pdfkit-tables in node.js

Time:03-15

I have API that generate pdf file after saving values into database. My customer needed to generate this pdf and then send it by mail. He sended my photo of how should that pdf look like. I recreated it, it looks same as in that picture but it is hard to read because there are missing vertical lines. I looked trought docs and also tried to google, bud I did not found anyithing. Here is how my PDF looks like:

PDF

As you can see, vertical lines are missing and because of that is harder to read.

Is there any possibility to add vertical lines?

Here is my code:

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();

I am using pdfkit-table package.

Thank you all

CodePudding user response:

By definition simple PDF structure is not tabular there is one cell (the page) and that one column can be subdivide into two or more rows with null spaces between the text sub columns.

That is why tables are difficult to sub[ex]tract

So adding coloured rows in one area is fairly simple to make like a table, thus to make vertical sub dividers is more difficult, However that feature was added in January 2022 enter image description here

For exsample see https://github.com/natancabral/pdfkit-table/issues/16#issuecomment-1012389097

  • Related