列在MPDF表中未正确显示

时间:2018-01-03 07:31:01

标签: html-table mpdf

我使用MPDF打印报告 我想只显示一次表头和表格体循环。
当我使用echo打印结果表时,它会显示正确,但是当我使用MPDF时,表格格式不正确。

Statement echo $ tr2。$ data2;显示适当的结构

Statement $ mpdf-> WriteHTML($ tr2。$ data2);显示折叠表

以下是我的代码:

for ($i = 0; $i < $totl_rows; $i++) {

        if($i == 0){
            $tr2 = '<table style="border-collapse: collapse; width: 100%; table-layout: fixed; " border="1" cellpadding="5"><tr>'
            . '<td style="width: 10%; font-weight: bold;">Consolidation Month</td>'
            .'<td style="width: 10%; font-weight: bold;">Transfer Entry No.</td>'
            . '<td style=" width: 10%;font-weight: bold;">Transfer Entry Dt.</td>'
            . '<td style=" width: 10%; font-weight: bold;">Amount</td>'
            . '<td style=" width: 10%;font-weight: bold;">Grant No.</td>'
            . '<td style=" width: 10%;font-weight: bold;">Fun Head No.</td>'
            . '<td style=" width: 10%;font-weight: bold;">Object Code</td>'
            . '<td style=" width: 10%;font-weight: bold;">Category Code</td>'
            . '<td style=" width: 10%;font-weight: bold;">UTL Trans Type</td>'
            . '<td style=" width: 10%;font-weight: bold;">UTL Dt.</td>'
            . '<td style=" width: 10%;font-weight: bold;">Utilised Amount</td></tr>';
        }
        else {
             $tr2= "<table  style='border-collapse: collapse; width: 100%; table-layout: fixed;' border='1'><tr></tr>";
        }
        $data2 = '<tr>'
                . '<td style=" width: 10%;">' . $consolidationmonth[$i] . '</td>'
                . '<td style=" width: 10%;">' . $tenumber[$i] . '</td>'
                . '<td style=" width: 10%;">' . $tedate1[$i] . '</td>'
                . '<td style=" width: 10%;">' . $amount[$i] . '</td>'
                . '<td style=" width: 10%;">' . $grantno[$i] . '</td>'
                . '<td style=" width: 10%;">' . $funcheadno[$i] . '</td>'
                . '<td style=" width: 10%;">' . $objectcode[$i] . '</td>'
                . '<td style=" width: 10%;">' . $categorycode[$i] .'</td>'
                . '<td style=" width: 10%;">' . $utl_trans_type[$i] . '</td>'
                  .'<td style=" width: 10%;">' . $utl_datee[$i] . '</td>'
                . '<td style=" width: 10%;">'. $utilised_amount[$i] . '</td></tr></table>';
        echo $tr2.$data2;
        $mpdf->WriteHTML($tr2.$data2);
    }

1 个答案:

答案 0 :(得分:0)

include("mpdf60/mpdf.php");
$mpdf=new mPDF('c'); 


$tr2 = '';
$data2 = '';

for ($i = 0; $i < $totl_rows; $i++) {
    if($i == 0){

        // *** INICIALIZA TABLA Y ENCABEZADOS (TABLE/HEAD) ***

        $tr2 = '<table style="border-collapse: collapse; width: 100%; table-layout: fixed; " border="1" cellpadding="5"><tr>'
        . '<td style="width: 10%; font-weight: bold;">Consolidation Month</td>'
        .'<td style="width: 10%; font-weight: bold;">Transfer Entry No.</td>'
        . '<td style=" width: 10%;font-weight: bold;">Transfer Entry Dt.</td>'
        . '<td style=" width: 10%; font-weight: bold;">Amount</td>'
        . '<td style=" width: 10%;font-weight: bold;">Grant No.</td>'
        . '<td style=" width: 10%;font-weight: bold;">Fun Head No.</td>'
        . '<td style=" width: 10%;font-weight: bold;">Object Code</td>'
        . '<td style=" width: 10%;font-weight: bold;">Category Code</td>'
        . '<td style=" width: 10%;font-weight: bold;">UTL Trans Type</td>'
        . '<td style=" width: 10%;font-weight: bold;">UTL Dt.</td>'
        . '<td style=" width: 10%;font-weight: bold;">Utilised Amount</td></tr>';
    }
    else {

        // *** ROWS ** FILAS ****

        $data2 .= '<tr>'
            . '<td style=" width: 10%;">' . $consolidationmonth[$i] . '</td>'
            . '<td style=" width: 10%;">' . $tenumber[$i] . '</td>'
            . '<td style=" width: 10%;">' . $tedate1[$i]  . '</td>'
            . '<td style=" width: 10%;">' . $amount[$i]   . '</td>'
            . '<td style=" width: 10%;">' . $grantno[$i]  . '</td>'
            . '<td style=" width: 10%;">' . $funcheadno[$i]    . '</td>'
            . '<td style=" width: 10%;">' . $objectcode[$i]    . '</td>'
            . '<td style=" width: 10%;">' . $categorycode[$i]  .'</td>'
            . '<td style=" width: 10%;">' . $utl_trans_type[$i] . '</td>'
              .'<td style=" width: 10%;">' . $utl_datee[$i]     . '</td>'
            . '<td style=" width: 10%;">'.   $utilised_amount[$i] . '</td></tr>';
    }   

}
// ** CIERRA TABLA ***
$data2 .= '</table>';

$mpdf->WriteHTML($tr2.$data2);
$mpdf->Output();