php – TCPDF – 有没有办法调整单表行高?
发布时间:2020-12-13 22:35:00 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试两天,没有结果,在表中调整单行最小高度,但没有成功. 我使用以下方法来创建我的表: ?php $html = EODtable style="border:1px solid black;" tr td Text 1 /td td Text 2 /td /tr /tableEOD;$this-writeHTMLCell($w=0,$h=0,$x='',$y='',$html,$bor
我正在尝试两天,没有结果,在表中调整单行最小高度,但没有成功.
我使用以下方法来创建我的表: <?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); ?> 我已经尝试设置td填充,td边距,td高度,tr高度,但没有成功.我也尝试过CSS和HTML.我唯一能做到的就是看到一行的高度大于原始值,但我想缩短它.我尝试在TCPDF的文档中搜索,但我发现唯一的事情是TCPDF不支持填充和边距.你们中的任何人都知道某种“黑客”来实现我想要的结果吗?
您可能遇到的是文本行的实际高度.在内部,TCPDF使用单元格高度比来控制渲染的线高.如果您的TD具有单行文本,则可以使用的最小值是行的总高度.所以td单元的最小尺寸是fontsize * cellheightratio任何被禁止的cellpadding
cellpadding可以来自cellpadding属性,因此我为此示例将其设置为0.我相信在编写HTML之前,至少还可以使用setCellPaddings设置一些填充维度. 您可以使用行高CSS声明来设置单元格高度比,以使行更小. (当然,您也可以减小字体大小.) <?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,$autopadding=true); 我的5.9.206安装上面的代码产生了这个: 这适用于第1行很大,是字体大小的两倍.第2行将行高设置为字体大小的100%.第3行是80%.第4行有50%. *请注意,如果你的文字包装,它会在非常低的线高处看起来很糟糕. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |