tcpdf html table,php - TCPDF split html table on multiple pages - Stack Overflow

I use TCPDF for outputting an html table, this one in my example is not the only one that i would have to modify so i need some rules for my pages to be rendered.

So far TCPDF seemed to me a powerfull library so i would appreciate not to try another one.

My issue is that i need to add the table header to every new page the table will appear to, but i have also other info to write to this pdf, that must not have the table header so i cannot use the rewrite of header method in tcpdf.

Nr.DenumireCodCant.Pret unitar
fara TVA (RON)
Pret total
fara TVA (RON)
      
1sectiune1 
1.1UNI-Cazan mixt AIREX 25 2S BICOMB MODUL 94456 9999924.623,002.462.275.377,00
1.2UNI-Cazan mixt AIREX 25 2S BICOMB MODUL 94456 9999924.623,002.462.275.377,00
  TOTAL sectiune1:    4.924.550.754,00
   
2sectiune2 
2.1ICI-Cazan condensatie MONOLITE 75-JB81020076 9999934.719,003.471.865.281,00
  TOTAL sectiune2:    3.471.865.281,00
   
Total sectiune1: 4.924.550.754,00
Total sectiune2: 3.471.865.281,00
Total oferta (RON):8.396.416.035,00
Total oferta (RON cu TVA inclus):10.411.555.883,40

I thought of the following solution: if somehow i could split this html to rows and write row by row to pdf so that i can rollback when i write over the footer and then i add a new page, but there is a major problem, i get all sorts of warnings because the html table tags are not closed.

Here is my code:

$pdf->setAutoPageBreak(false);

$pdf->startTransaction();

$html = new simple_html_dom();

$html->load($data);

$single = $html->find('#Container', 0);

if($single){

$rows = $single->getElementsByTagName('tr');

$rows = $rows[0]->getElementsByTagName('tr');

if($rows)

for($i=1;$i

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', '

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $rows[$i]->outertext, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', '

', $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);

if ($pdf->getY() > $pdf->getPageHeight() - 30) {

$pdf->rollbackTransaction(true);

$pdf->AddPage();

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', '

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $rows[$i]->outertext, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', '

', $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=false);

}

}

}

$pdf->commitTransaction();

$pdf->setAutoPageBreak(true, 30);

I took a quick look at this 2 articles, maybe someone could find this handy:

Some paging with multicell

and Another paging with multicell . I found this 2 worthy of an example as a solution logic, but the methods used with tcpdf seemed to me a little weird.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值