0

I am working on invoice printout.

I am facing a problem in printing the invoice. let's say there is an invoice that consist of items that are exactly in 1 page. The problem is there are subtotal, tax, and grandtotal after all the items.

In this case these 3 would be on the second page(new page), while the items are on 1st page.

I have done checking the row that one page can hold in tcpdf(after all my layout format, etc) and found out 1 page will consist of 28 items. This will work well if all the item consists of 1 row. However, if some of the items consist of 2 or more rows, the calculation will face a problem, and the whole structure will be a mess.

How can i automatically move some items to second page if the total items are 28 items, so the second page will not only consist of the subtotal, tax, and grand total?

here is my code

$count = 0;
$i = 0;
if(count($finalProduct)>0){
foreach($finalProduct as $product){
    foreach($product['product'] as $prod){
        if($prod['qty'] > 0){

            /* check the row */
            if($count >= 27){
              $PDFCONTENT .= '<tr style="page-break-after:initial"><td colspan="6"></td></tr>';
              $PDFCONTENT .= '<tr><td colspan="6"></td></tr>';
              $count = 0;
            }

                $PDFCONTENT .= '
                    <tr nobr="true">';
                $PDFCONTENT .= '<td align="center" width="7%">'.$prod['index_number'].'</td>';
                                </tr>';
            }
            $count++;
        }
        $PDFCONTENT .= '<tr><td></td></tr>';
    }
    }
    $PDFCONTENT .= '<tfoot>
    <tr> <td> </td> </tr>
    <tr>
    <th align="right" colspan="6">SUB TOTAL $:-</th>
    <th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['total'],2).'</th>
</tr>
    <tr>
    <th align="right" colspan="6">ADD '.number_format($data['transaction_tax_percentage']).'% $:-</th>
    <th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['transaction_tax_amount'],2).'</th>
</tr>
    <tr>
    <th align="right" colspan="6">TOTAL $:-</th>
    <th style="border-top: 1px solid black;border-bottom: 1px solid black;" align="center">'.number_format($data['grand_total'],2).'</th>
</tr>
</tfoot>';
Foster
  • 345
  • 1
  • 5
  • 18

1 Answers1

1

I remember that this was a real problem with tables. so we calculatet if there is a pagebreak to be set. If so, we closed the tabel, added a new site and reopened the table and put the rest of the table in it.

To force the pagebreak we used <br pagebreak="true"/>

if you don't close the table it leads to other problems.

A good threat is also here on SO: Manual Page Break in TCPDF

Community
  • 1
  • 1
helle
  • 11,183
  • 9
  • 56
  • 83