【发布时间】:2020-03-05 05:05:57
【问题描述】:
我尝试使用 writeHTML 方法在 TCPDF 中生成一些文本信息。但是TCPDF有时会在表格结构内自动分页后创建额外的空白页(我使用表格相关标签来格式化文本位置)。
Bug 示例截图:
更新:这是简化的代码示例:
<?php
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetMargins('20', '20', '15');
$pdf->SetAutoPageBreak(true, '25');
$pdf->SetFont('freeserif', '', 11);
$pdf->AddPage();
$tagvs = array(
'p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 1, 'n' => 1)),
'ul' => array(0 => array('h' => 0.0001, 'n' => 1), 1 => array('h' => 1, 'n' => 1)),
'ol' => array(0 => array('h' => 0.0001, 'n' => 1), 1 => array('h' => 1, 'n' => 1)),
'div' => array(0 => array('h' => 0.0001, 'n' => 1), 1 => array('h' => 0.0001, 'n' => 1)),
'hr' => array(0 => array('h' => 0.0001, 'n' => 1), 1 => array('h' => 0.0001, 'n' => 1)),
);
$pdf->setHtmlVSpace($tagvs);
$html = '<p>Some Content</p><table><tbody><tr><td>Some content</td><td>Some content</td></tr>';
//READ NEXT LINE PLEASE
$html .= '<tr><td>BEFORE THIS TR COULD BE BLANK PAGE IN GENERATED PDF</td><td>IT DEPENDS OF TABLE CONTENT LENGTH</td></tr>';
//READ PREVIOUS LINE PLEASE
$html .= '<tr><td>Some content</td><td>Some content</td></tr></tbody></table><p>Some Content</p><p>Some Content</p>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('document.pdf', 'I');
?>
更新:更具示范性的屏幕截图: Table cell is going to the end of the page
我该如何避免呢?非常感谢!
【问题讨论】:
-
你能分享你正在使用的代码吗?我们不可能在没有看到代码的情况下告诉您是什么原因造成的
-
我刚刚更新了我的帖子并添加了代码。
-
刚刚在我的第一篇文章中添加了更具示范性的新截图。
-
SetAutoPageBreak是我要看的地方。如果将SetAutoPageBreak设置为false会发生什么?在我所有的 PDF 工作中,我倾向于将SetAutoPageBreak设置为false,除非我有很长的文本,但我还不知道它的长度。 -
@conradkdotcom 我生成的 PDF 可能长达 100 页。所以我需要使用
SetAutoPageBreak函数。