Ada*_*yai 7 html css php tcpdf
我正在尝试两天,没有结果,在表中调整单行最小高度,但没有成功.
我使用以下方法来创建我的表:
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
我已经尝试设置td填充,td边距,td高度,tr高度,但没有成功.我也尝试过CSS和HTML.我唯一能做到的就是看到一行的高度大于原始值,但我想缩短它.我尝试在TCPDF的文档中搜索,但我发现唯一的事情是TCPDF不支持填充和边距.你们中的任何人都知道某种"黑客"来实现我想要的结果吗?
EPB*_*EPB 28
您可能遇到的是文本行的实际高度.在内部,TCPDF使用单元格高度比来控制渲染的线高.如果您的TD具有单行文本,则可以使用的最小值是行的总高度.所以td单元格的最小尺寸是fontsize * cellheightratio + any cellpadding proscribed
cellpadding可以来自cellpadding属性,因此我为此示例将其设置为0.我相信在setCellPaddings编写HTML之前,至少还可以设置一些填充维度.
您可以使用line-heightCSS声明来设置单元格高度比,以使行更小.(当然,您也可以减小字体大小.)
<?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);
Run Code Online (Sandbox Code Playgroud)
我的5.9.206安装上面的代码产生了这个:

这适用于第1行很大,是字体大小的两倍.第2行将行高设置为字体大小的100%.第3行是80%.第4行有50%.
*请注意,如果你的文字包装,它会在非常低的线高处看起来很糟糕.
| 归档时间: |
|
| 查看次数: |
21396 次 |
| 最近记录: |