Pdfmake: Center table on print

Created on 22 Apr 2018  路  3Comments  路  Source: bpampuch/pdfmake

Trying to center a full table on print, instead of aligning to the left with content:
Have tried adding the following code in bold but doesn't do anything for me.

I also have a variable amount of columns for all my tables, is there a way to make something like this work for every table?

$('#myTable').DataTable( {
    buttons: [
        {   content: [
                        {
                    'alignment': 'center',
                        table: {
                        body: [
                            ['Column 1', 'Column 2', 'Column 3'],
                            ['One value goes here', 'Another one here', 'OK?']
                                ]
                                }
                              }
                      ],
            extend: 'pdfHtml5',
            text: 'Save current page',
            exportOptions: {
                modifier: {
                    page: 'current'
                }
            }
        }
    ]
} );

Most helpful comment

Table aligment issue https://github.com/bpampuch/pdfmake/issues/72 exists, but use this workaround:

var dd = {
    content: [
        {
            columns: [
                { width: '*', text: '' },
                {
                    width: 'auto',
                        table: {
                                body: [
                                        ['Column 1', 'Column 2', 'Column 3'],
                                        ['One value goes here', 'Another one here', 'OK?']
                                ]
                        }
                },
                { width: '*', text: '' },
            ]
        }
    ]
}

All 3 comments

Table aligment issue https://github.com/bpampuch/pdfmake/issues/72 exists, but use this workaround:

var dd = {
    content: [
        {
            columns: [
                { width: '*', text: '' },
                {
                    width: 'auto',
                        table: {
                                body: [
                                        ['Column 1', 'Column 2', 'Column 3'],
                                        ['One value goes here', 'Another one here', 'OK?']
                                ]
                        }
                },
                { width: '*', text: '' },
            ]
        }
    ]
}

Thanks, but I can't seem to combine your code with my code above and I've tried for an hour now (and some hours yesterday).
How would it all look together? I am using DataTables above.

I don't use DataTable library so I do not know. Ask on DataTable support.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

qgliu picture qgliu  路  3Comments

ValeSauer picture ValeSauer  路  3Comments

CharlyPoppins picture CharlyPoppins  路  3Comments

SummerSonnet picture SummerSonnet  路  3Comments

Christian24 picture Christian24  路  3Comments