php - TCPDF 的 getNumLines() 有时会出错

标签 php pdf tcpdf

我在编写文本之前使用 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/

相关文章:

php - 使用 PHP 使用 mysql pdo 中的数据生成 XML

php - FPDF 中的新行

php - 如何在 PHP 中对以逗号分隔的字符串进行排序?

php - TCPDF不能显示¥,其他汉字可以

php - TCPDF 浏览器弹出标题

php - 如何从javascript调用表单提交?

c# - 使用 iText 7 创建的可见签名未在 chrome 中显示

pdf - 使用 flutter 打印包,如何从 URL 打印 PDF?

javascript - 将多个 Highcharts 导出为多页 PDF

php - 如何解决在 tcpdf 中添加自定义字体会导致点状输出?