pdf-php icon indicating copy to clipboard operation
pdf-php copied to clipboard

Numbers are not right-aligning in table

Open RPort71 opened this issue 1 year ago • 2 comments

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: image

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.

RPort71 avatar Jan 18 '24 09:01 RPort71

$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 ] );`

ole1986 avatar Jan 18 '24 21:01 ole1986

Thank you for the reply. I tried that and the numbers are still being left aligned.

RPort71 avatar Jan 19 '24 11:01 RPort71

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) ] );

AlainC-be avatar Sep 20 '25 08:09 AlainC-be

Thank you for the response. I don't remember what the resolution was in this case, but it was solved almost a year ago

RPort71 avatar Sep 20 '25 16:09 RPort71