php – TCPDF – 有没有办法调整单表行高?

前端之家收集整理的这篇文章主要介绍了php – TCPDF – 有没有办法调整单表行高?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试两天,没有结果,在表中调整单行最小高度,但没有成功.

我使用以下方法来创建我的表:

  1. <?PHP
  2. $html = <<<EOD
  3. <table style="border:1px solid black;">
  4. <tr>
  5. <td>
  6. Text 1
  7. </td>
  8. <td>
  9. Text 2
  10. </td>
  11. </tr>
  12. </table>
  13. EOD;
  14.  
  15. $this->writeHTMLCell($w=0,$h=0,$x='',$y='',$html,$border=0,$ln=1,$fill=0,$reseth=true,$align='',$autopadding=true);
  16. ?>

我已经尝试设置td填充,td边距,td高度,tr高度,但没有成功.我也尝试过CSS和HTML.我唯一能做到的就是看到一行的高度大于原始值,但我想缩短它.我尝试在TCPDF的文档中搜索,但我发现唯一的事情是TCPDF不支持填充和边距.你们中的任何人都知道某种“黑客”来实现我想要的结果吗?

您可能遇到的是文本行的实际高度.在内部,TCPDF使用单元格高度比来控制渲染的线高.如果您的TD具有单行文本,则可以使用的最小值是行的总高度.所以td单元的最小尺寸是fontsize * cellheightratio任何被禁止的cellpadding

cellpadding可以来自cellpadding属性,因此我为此示例将其设置为0.我相信在编写HTML之前,至少还可以使用setCellPaddings设置一些填充维度.

您可以使用行高CSS声明来设置单元格高度比,以使行更小. (当然,您也可以减小字体大小.)

  1. <?PHP
  2.  
  3. //For demonstration purposes,set line-height to be double the font size.
  4. //You probably DON'T want to include this line unless you need really spaced
  5. //out lines.
  6. $this->setCellHeightRatio(2);
  7.  
  8. //Note that TCPDF will display whitespace from the beginning and ending
  9. //of TD cells,at least as of version 5.9.206,so I removed it.
  10. $html = <<<EOD
  11. <table style="border:1px solid black;" border="1" cellpadding="0">
  12. <tr>
  13. <td>Row 1,Cell 1</td>
  14. <td>Row 1,Cell 2</td>
  15. </tr>
  16. <tr style="line-height: 100%;">
  17. <td>Row 2,Cell 1</td>
  18. <td>Row 2,Cell 2</td>
  19. </tr>
  20. <tr style="line-height: 80%;">
  21. <td>Row 3,Cell 1</td>
  22. <td>Row 3,Cell 2</td>
  23. </tr>
  24. <tr style="line-height: 50%;">
  25. <td>Row 4,Cell 1</td>
  26. <td>Row 4,Cell 2</td>
  27. </tr>
  28. </table>
  29. EOD;
  30.  
  31. $this->writeHTMLCell($w=0,$autopadding=true);

我的5.9.206安装上面的代码产生了这个:

这适用于第1行很大,是字体大小的两倍.第2行将行高设置为字体大小的100%.第3行是80%.第4行有50%.

*请注意,如果你的文字包装,它会在非常低的线高处看起来很糟糕.

猜你在找的PHP相关文章