TCPDF的getNumLines()有时是错误的 [英] TCPDF's getNumLines() is sometimes wrong
问题描述
我使用getNumLines()
来估计写入文本之前的行数,因为必须相应地放置它.
似乎getNumLines()计算出的文本空间要多于MultiCell()
实际需要的空间.用MultiCell()
编写时仍然适合单元格的一长行似乎被getNumLines()
软包装了:
I use getNumLines()
to estimate the number of lines before writing the text, besause it has to be positioned accordingly.
It seems that getNumLines() calculates more space for the text then MultiCell()
actually needs. A long line, that still fits into the cell when writing with MultiCell()
seems to be soft-wrapped by getNumLines()
:
$lines = $pdf->getNumLines($text, $width);
$pdf->MultiCell($width, 50, $text, 0, "L");
在我的测试中,$lines
是3,而只打印了2行.如果我稍微增加$ width,我会得到正确的值.第一行是更长的行.因此,包装的末尾不能成为非打印字符.
In my test $lines
is 3 while only 2 lines are printed. If I increase the $width a bit I get the right value. And it is the first line that is the longer one. So it can't be a non-printing-character in the end that is wrapped.
也许是因为我传递给MultiCell()
的align参数"L"?但是getNumLines()
没有这样的建议吗?
Maybe it's because of the align parameter "L" I pass to MultiCell()
? But there isn't such for getNumLines()
... any suggestions?
TCPDF版本:5.9.156
Version of TCPDF: 5.9.156
推荐答案
哈!发现了错误:getNumLines()
计算换行符和回车符的空间.
Ha! Found the bug: getNumLines()
calculates space for newlines and carriage returns.
为避免这种情况,我编辑了字体定义文件:有一个名为$cw
的数组,用于定义每个字符的宽度.我添加了两个条目:10 => 0, 13 => 0
将换行符的宽度和回车符设置为零.
To avoid this I edited the font definition files: There is an array called $cw
defining the width of each character. I added two entries: 10 => 0, 13 => 0
to set the width of newline and carriage return to zero.
这篇关于TCPDF的getNumLines()有时是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!