writeHTMLCell上的TCPDF rollbackTransaction

时间:2016-03-30 10:30:27

标签: php tcpdf rollback

我正在使用TCPDF运行以下情况: 尝试通过计算每个writeHTMLCell

上的Y值来创建一个表并将其从底部剪掉

首先是代码:

// test the buffer with extra line
$this->pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_buffer.$row.'</table>', $border=0, $ln=1, $fill=1, $reseth=true, $align='', $autopadding=false); 

if ($this->pdf->getY() < ($this->pdf->getPageHeight() - 100)) { // Note the less-than operator
    // We might be able to add some more text, so undo that
    $this->pdf->rollbackTransaction(true);
    // And store the html
    $html_buffer .= $row;
}else{
    // We exceeded our limit
    $this->pdf->rollbackTransaction(true);
    // Write last known good table
    $this->pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html_buffer.'</table>', $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);
    // Add a new page
    $this->pdf->AddPage();
    // End this transaction
    $this->pdf->commitTransaction();
    // Start a new transaction
    $this->pdf->startTransaction();
    // Reset html buffer
    $html_buffer = '<table>';
    // Add line we couldn't fit on last page to html buffer
    $html_buffer .= $row;
}

(来自TCPDF split html table on multiple pages

但是output-pdf也显示了第一个writeHTMLCell的结果,它仅用于测试Y值。 回滚似乎无法正常工作?

输出如下:

row 1
row 1
row 2
row 1
row 2
row 3
row 1
row 2
row 3
row 4

任何出错的线索?

0 个答案:

没有答案