【问题标题】:PHP TCPDF unwanted blank page inside HTML markupHTML标记内的PHP TCPDF不需要的空白页
【发布时间】: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函数。

标签: php html tcpdf


【解决方案1】:

似乎在表格单元格内容的最后一个标签中添加style="page-break-inside: avoid;" 可以解决问题。

<td>
    <span>Some content here</span>
    <p>Another content</p>
    <div>One more content</div>
    <p style="page-break-inside: avoid;">Such tag does the thing!</p>
</td>

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    相关资源
    最近更新 更多