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.
|
|
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.