Skip to content
Advertisement

TCPDF – loop data in two columns layout

Im using TCPDF, at the moment im a listing data in two columns using array_chunk which works fine. But i need data to be show in first columns and then second, see below:

Currently:
    1   2
    3   4
    5   6
    7   8
    9   10
Should be:
    1   6
    2   7
    3   8
    4   9
    5   10

This is the code:

<?php   $array = range(1, 50);?>
<table nobr="true" cellpadding="2">
     <?php foreach (array_chunk($array, 2) as $a) { ?>
        <tr>
        <?php foreach ($a as $array_chunk) { ?>
           <td><?php echo $array_chunk; ?></td>
            <?php
         } ?>
       </tr>
       <?php }    ?>
</table>

my second query(complex) if there are more than 30 rows i need to be able to use $pdf->AddPage(); and continues on the next page.

Advertisement

Answer

TCPDF – support multicolumns, this is wat i used to solve my issue:

$pdf->AddPage();
$pdf->resetColumns();
$pdf->setEqualColumns(2, 84);  // KEY PART -  number of cols and width
$pdf->selectColumn();               
$content =' loop content here';
$pdf->writeHTML($content, true, false, true, false);
$pdf->resetColumns()

the code will add auto page break and continues to next page.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement