Pdfmake center table

pdfmake: Center Table

pdfmake is a JavaScript library that allows you to generate PDF files programmatically in the browser.

To create a table and center it within the PDF document, you can use the `layout` property of the `table` object in pdfmake.

Here is an example:

  var docDefinition = {
    content: [
      {
        layout: 'lightHorizontalLines', // Define the table layout
        table: {
          widths: ['*', '*', '*'], // Define column widths
          body: [
            ['Column 1', 'Column 2', 'Column 3'],
            ['Data 1', 'Data 2', 'Data 3'],
            ['Data 4', 'Data 5', 'Data 6']
          ]
        }
      }
    ]
  };

  // Generate the PDF
  pdfMake.createPdf(docDefinition).download();
  

In this example, the `layout` property is set to ‘lightHorizontalLines’, which will add horizontal lines to the table. You can use other table layouts or define your own custom layout.

The `table` property contains the table data. In this case, it has three columns with widths defined as ‘*’ (equal width for all columns). The `body` property of the table contains the actual data rows.

Once you have defined the document structure using `docDefinition`, you can generate the PDF by calling the `createPdf` method and download it using the `download` function.

Make sure to include the pdfmake library in your HTML file by adding the following script tag:

  
  

Also, refer to the official documentation of pdfmake for more advanced usage and customization options.

Leave a comment