Emmanuel Oliveira
Emmanuel Oliveira

Reputation: 164

How to center align table - PDFMAKE

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.

Upvotes: 6

Views: 19786

Answers (2)

sadati boina
sadati boina

Reputation: 635

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

Upvotes: -2

ImtiazNur
ImtiazNur

Reputation: 260

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: '' },
    ]
}

Upvotes: 22

Related Questions