Numbers are not right-aligning in table
I have built many PDFs using Cezpdf, but I'm stuck on this one issue now.
My code is as follows:
$columnWidth = 40;
$vatHeadersConfiguration = [];
if( !$isIECompany ){
$vatHeadersConfiguration['vat_rate'] = ['justification' => 'right', 'width' => $columnWidth];
}
$vatHeadersConfiguration['vat_amount'] = ['justification' => 'right', 'width' => $columnWidth];
$cols = [
'desc' => ['justification' => 'left', 'width' => 290],
'qty' => ['justification' => 'center', 'width' => $columnWidth],
'each' => ['justification' => 'right', 'width' => $columnWidth],
];
if (!$isIECompany || !$sharedCharges) {
$cols['tot'] = ['justification' => 'right', 'width' => $columnWidth];
}
$columns = [
'cols' => array_merge($cols, $vatHeadersConfiguration)
];
$pdfobj->ezTable($invoiceData,
$tableHeaders,
'',
[
'lineCol' => [0.8, 0.8, 0.8],
'width' => 530,
'shaded' => 0,
$columns
]
);`
When I test the PDF, I get this:
I don't understand why the numbers are not right-aligned. I tried changing
array_merge($cols, $vatHeadersConfiguration)
to
$cols + $vatHeadersConfiguration
but it didn't make a difference.
Any help would be much appreciated. Thank you.
$pdfobj->ezTable($invoiceData, $tableHeaders, '', [ 'lineCol' => [0.8, 0.8, 0.8], 'width' => 530, 'shaded' => 0, $columns ] );
Should be
$pdfobj->ezTable($invoiceData, $tableHeaders, '', [ 'lineCol' => [0.8, 0.8, 0.8], 'width' => 530, 'shaded' => 0, 'cols' => $columns ] );`
Thank you for the reply. I tried that and the numbers are still being left aligned.
Also late, but this shouldn't be left open either ... The array_merge made a array of an array int the wrong way.
Could have been directly in the ezTable call.
$pdfobj->ezTable($invoiceData, $tableHeaders, '', [ 'lineCol' => [0.8, 0.8, 0.8], 'width' => 530, 'shaded' => 0, 'cols' => array_merge($cols, $vatHeadersConfiguration) ] );
Thank you for the response. I don't remember what the resolution was in this case, but it was solved almost a year ago