0

I'm using TCPDF to render list of products and their available SKUs.

As the attached image below:

  • "Product name" (P1) will be displayed in a row.
  • "N of SKUs" (P2) will be displayed in N row.

enter image description here

Using attribute nobr="true" for td tag, I can avoid a row split into separated page. However, it makes P1 and rows of P2 break page in some cases.

Code example (Laravel blade):

<tr nobr="true">
  <td>{{ $product->name }}</td>
  <td>{{ $otherInfo }}</td>
</tr>

@foreach ($product->skus as $sku)
  <tr nobr="true">
    <td>{{ $sku->number }}</td>
    <td>{{ $sku->quantity }}</td>
  </tr>
@endforeach

I would like to make the block of P1 and P2 same page. If the block's height exceeded bottom margin, they should be moved to next page.

Do you guys have any solutions or keywords to solve this problem?
Many thanks for your help!

Thanh Dao
  • 1,218
  • 2
  • 16
  • 43
  • I believe you might be able to use the page-break style here within your PDF. Here is another similar question to yours that might hopefully help: https://stackoverflow.com/questions/1605860/manual-page-break-in-tcpdf#:~:text=Use%20%24tcpdf%2D%3EAddPage(),reduce%20the%20number%20into%200. – Luke Sep 08 '22 at 07:55

1 Answers1

0

Sorry, can't comment yet. Best would be to apply nobr="true" to the tbody tag, but unfortunately that is not implemented into tcpdf. BUT you can apply nobr="true" to the table tag. Which means, if you have fixed width for the complete table you can concatenate seamlessly two tables. Of which the one with these two Product names you want to stick together get their own table plus the nobreak.

TTorai
  • 84
  • 6