pdfmake icon indicating copy to clipboard operation
pdfmake copied to clipboard

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

Open mithun146 opened this issue 9 years ago • 6 comments

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'
	}
	
}

mithun146 avatar Apr 26 '17 13:04 mithun146

overflow

mithun146 avatar Apr 26 '17 13:04 mithun146

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

VojtaStanek avatar Apr 30 '17 21:04 VojtaStanek

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.

mithun146 avatar May 02 '17 13:05 mithun146

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

liborm85 avatar May 04 '17 08:05 liborm85

@Cactucs Thank you Bro

saikishoreMeda avatar Mar 21 '19 12:03 saikishoreMeda

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

awais2080 avatar Jun 18 '19 19:06 awais2080