Pdfmake: is there any way to set the table width in percentage, in order to avoid the overflow.

Created on 26 Apr 2017  路  6Comments  路  Source: bpampuch/pdfmake

Here below you can see the code. The table content actually overflows. Any way to fit the table into the pdf.

// playground requires you to assign document definition to a variable called dd
var data = {'title':'MachineHoursReport','author':'Hyva','headerMargin':[40,15,0,0],'headerImage':'/images/bull_machines_logo.png','headerText':'Machine Hours Report','footerText':'Copyright 2017 Bullindia.com','footerMargin':[40,0,0,0],'contentHeaderRows':1,'contentWidth':[],'contentBody':{'tableData':[[{'text':'Machine Name','style':'tableHeaders'},{'text':'Total Machine Life','style':'tableHeaders'},{'text':'Machine Hours','style':'tableHeaders'},{'text':'Last Received Status','style':'tableHeaders'},{'text':'Last Engine Run','style':'tableHeaders'},{'text':'Last Reported','style':'tableHeaders'},{'text':'Location','style':'tableHeaders'},{'text':'Dealer Name','style':'tableHeaders'}],[{'text':'HAR3DXSSK01896684HAR3DXSSK01896684','style':'bodyStyle'},{'text':1152,'style':'bodyStyle'},{'text':123,'style':'bodyStyle'},{'text':'ON','style':'bodyStyle'},{'text':'09/07/2018','style':'bodyStyle'},{'text':'09/07/2018','style':'bodyStyle'},{'text':'TRR Automative','style':'bodyStyle'}]]},'isDatePresent':{'flag':false,'date':''}};
var dd = {
    content: [
        {text: 'Tables', style: 'header'},
        {
            style: 'tableExample',
            table: {
                body: [
                            ['Col1', 'Col2', 'Col3'],
                                        ['HAR3DXSSK01896684HAR3DXSSK01896684', 'HAR3DXSSK01896684HAR3DXSSK01896684', 'HAR3DXSSK01896684HAR3DXSSK01896684'],
                                        ['1', '2', '3']
                      ]
            } 
        }


    ],
    styles: {
        header: {
            fontSize: 18,
            bold: true,
            margin: [0, 0, 0, 10]
        },
        subheader: {
            fontSize: 16,
            bold: true,
            margin: [0, 10, 0, 5]
        },
        tableExample: {
            margin: [0, 5, 0, 15],
            widths: '*'
        },
        tableHeader: {
            bold: true,
            fontSize: 13,
            color: 'black'
        }
    },
    defaultStyle: {
        // alignment: 'justify'
    }

}

Most helpful comment

You can try setting something likewidths: ['16.6%', '16.6%', '16.6%', '16.6%', '16.6%', '16.6%'] inside table

All 6 comments

overflow

You can try setting something likewidths: ['16.6%', '16.6%', '16.6%', '16.6%', '16.6%', '16.6%'] inside table

hows does that above code works? setting width for the table column ? I have tried _widths_ some time back, but it was not working as expected.

Long words do not wraps, its known problem: https://github.com/bpampuch/pdfmake/issues/204

@Cactucs Thank you Bro

You can try setting something likewidths: ['16.6%', '16.6%', '16.6%', '16.6%', '16.6%', '16.6%'] inside table

you saved my day buddy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmatesic picture dmatesic  路  3Comments

kumarandena picture kumarandena  路  3Comments

davidyeiser picture davidyeiser  路  3Comments

svenyonson picture svenyonson  路  3Comments

einfallstoll picture einfallstoll  路  3Comments