TCPDF Is there a way to adjust the row height of a table?

I have been trying for two days, without any results, to adjust the minimum row height in the table, without any success.

I use the following method to create my table:

<?php $html = <<<EOD <table style="border:1px solid black;"> <tr> <td> Text 1 </td> <td> Text 2 </td> </tr> </table> EOD; $this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); ?> 

I already tried installing td padding, td margin, td height, tr height, without success. I also tried them from CSS and HTML. The only thing I managed to achieve was to see the line height greater than the original value, but I want to make it shorter. I tried searching the TCPDF documentation, but the only thing I found was that TCPDF does not support padding and margins. Do any of you know some kind of “hack” to achieve the desired result?

+6
source share
1 answer

What you are probably using is the actual height of the lines of text. Internally, TCPDF uses the cell height ratio to control the height of the render line. When you have a TD with one line of text, the smallest of which you can do is the total height of the line. So the minimum cell size td is fontsize * cellheightratio + any cellpadding proscribed

cellpadding can come from the cellpadding attribute, so I set this example to 0. In my opinion, at least some of the padding parameters can also be set using setCellPaddings before writing HTML.

You can set the cell height ratio using CSS line-height declaration to reduce the number of rows. (You can, of course, just decrease the font size.)

 <?php //For demonstration purposes, set line-height to be double the font size. //You probably DON'T want to include this line unless you need really spaced //out lines. $this->setCellHeightRatio(2); //Note that TCPDF will display whitespace from the beginning and ending //of TD cells, at least as of version 5.9.206, so I removed it. $html = <<<EOD <table style="border:1px solid black;" border="1" cellpadding="0"> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> <tr style="line-height: 100%;"> <td>Row 2, Cell 1</td> <td>Row 2, Cell 2</td> </tr> <tr style="line-height: 80%;"> <td>Row 3, Cell 1</td> <td>Row 3, Cell 2</td> </tr> <tr style="line-height: 50%;"> <td>Row 4, Cell 1</td> <td>Row 4, Cell 2</td> </tr> </table> EOD; $this->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); 

The above code on my installation of 5.9.206 creates the following: Visual example of set line-heights.

This works so that line 1 is large, twice the font size. Line 2 sets the height of the line so that it is 100% of the font size. Line 3 is 80%. Line 4 is 50%.

* Please note that if your text wraps around, it will look terrible at very low line heights.

+23
source

Source: https://habr.com/ru/post/955660/


All Articles