我在编写文本之前使用 getNumLines() 来估计行数,因为它必须相应地定位。
看起来 getNumLines() 计算的文本空间比 MultiCell() 实际需要的空间更多。使用 MultiCell()
写入时仍然适合单元格的长线似乎被 getNumLines()
软包装:
$lines = $pdf->getNumLines($text, $width);
$pdf->MultiCell($width, 50, $text, 0, "L");
在我的测试中,$lines
为 3,而仅打印 2 行。如果我增加 $width 一点,我就会得到正确的值。第一条线较长。所以最后不可能是被换行的非打印字符。
也许是因为我传递给 MultiCell()
的对齐参数“L”?但是没有这样的 getNumLines()
...有什么建议吗?
TCPDF版本:5.9.156
最佳答案
this ticket的评论中描述了另一种技术。 tcpdf 的 bugtracker,听起来很有前途:
If you want o know the exact number of lines you have to use the following technique:
// store current object
$pdf->startTransaction();
// get the number of lines
$lines = $pdf->MultiCell($w, 0, $txt, 0, 'L', 0, 0, '', '', true, 0, false,true, 0);
// restore previous object
$pdf = $pdf->rollbackTransaction();
关于php - TCPDF 的 getNumLines() 有时会出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10952848/