6

Can i create one table with center alignment (page) using PDFMAKE?

Already defined alignment: "center" in Styles and inside the tag table: {}

{
              table: {
                width: "auto",
                body: [
                  [
                    { text: "PERÍODO", style: "tableHeader" },
                    { text: "VOLUME (MW médios)", style: "tableHeader" }
                  ],
                  ["{7} a {8}", "{9}"],
                  ["{10} a {11}", "{12}"],
                  ["{13} a {14}", "{15}"]
                ],
                alignment: "center"
              }
            }

I expect one table align in the center of the page.

Emmanuel Oliveira
  • 144
  • 1
  • 2
  • 14

2 Answers2

21

alignment:"center" only aligns the content of the columns in center. You can try as following:

{
    columns: [
        { width: '*', text: '' },
        {
            width: 'auto',
                table: {
                body: [
                  [
                    { text: "PERÍODO", style: "tableHeader" },
                    { text: "VOLUME (MW médios)", style: "tableHeader" }
                  ],
                  ["{7} a {8}", "{9}"],
                  ["{10} a {11}", "{12}"],
                  ["{13} a {14}", "{15}"]
                ],
                alignment: "center"
                }
        },
        { width: '*', text: '' },
    ]
}
Gaurav Jeswani
  • 4,410
  • 6
  • 26
  • 47
ImtiazNur
  • 250
  • 2
  • 13
  • Ingenious solution. Create 3 columns, 2 of them blank and in the center put the table with the alignment. works like a charm. – apereira Feb 04 '21 at 05:23
-2

It works with pdfmake-wrapper:

pdf.add(new Columns(
                    [new Txt("").width('*').end,
                    new Table([
                                [ 'column 1', 'column 2'],
                                [ 'column 1', 'column 2']
                              ]).width('auto').layout('noBorders').end,
                    new Txt("").width('*').end ]
                   ).end);
sadati boina
  • 625
  • 7
  • 10