表格内容未在tcpdf上正确显示

时间:2018-06-11 17:58:12

标签: php tcpdf

我正在尝试从以下PHP代码中打印pdf文件:

require_once('tcpdf/tcpdf.php');  
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  
$obj_pdf->SetCreator(PDF_CREATOR);   
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));  
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));  
$obj_pdf->SetDefaultMonospacedFont('helvetica');  
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '4', PDF_MARGIN_RIGHT);  
$obj_pdf->setPrintHeader(false);  
$obj_pdf->setPrintFooter(false);  
$obj_pdf->SetAutoPageBreak(TRUE, 10);  
$obj_pdf->SetFont('helvetica', '', 12);  
$obj_pdf->AddPage(); 
$sql = "SELECT * FROM donors WHERE user_name='$username'";
$result = mysqli_query($conn, $sql);
$html = '';
$html .= '


<!doctype html>
  <html lang="en">
   <head>

   <style>
.text-center{
    text-align: center;
}

.img-fluid{

    width: 200px;
    height: 41px;
}

.title{

    text-decoration: underline;
}

.text-left{

    text-align: left;
}




</style>

</head>
 <body>
<div >
    <div class="text-center">
        <div >
            <img src="img/logo.png" class="img-fluid">
        </div>
        <div class="title">
            <h1>Donation Report</h1>
        </div>
        <div >
            <h3 >';
    $html .= "Date : " . date("m-d-Y"); 
    $html .= '</h3>
        </div>
        <div class="text-left">
            <h4>Hello ';
    $html .= $_SESSION['u_user_name'];

    $html .= ',</h4>
            <p>Thanks a lot for donating and supporting us. Please find your 
    details below for tax filing:</p>
        </div>

        <div>
            <table border="1" cellspacing="0" cellpadding="5" id="box">
                <tr>
                    <td>Date</td>
                    <td>Amount</td>


                </tr>';

    $sql2 = "SELECT * FROM donors WHERE user_name='$username';";
    $result = mysqli_query($conn, $sql2);

    while($row = mysqli_fetch_assoc($result)){
        $array = explode('|',$row['donation_amount']);
        $array1 = explode('|',$row['date_donation']);
        $len=count($array1);
        for ($i=0;$i<$len;$i++){
    $html .= '<tr></td>'.$array1[$i].'</td><td>'. $array[$i]. '</td></tr>';
    }}






    $html .= '</table>';

    $html .= '<h5> Total Amount:' . $_SESSION['u_total'] . '</h5>';

    $html .=
        '</div>

        <div class=" text-left">
            <h4>Thanks and Regards,</h4>
            <h4>Detroit Pheonix Center</h4>
            <h4>Detroit, Mi</h4>

        </div>

    </div>

  </div>

</body>
</html>';


$obj_pdf->writeHTML($html); 



$obj_pdf->Output('donor_report.pdf', 'I');

最初,我收到了这个错误:

TCPDF错误:某些数据已经输出,无法发送PDF文件

后来我用了ob_end_clean(); pdf输出前的命令。我得到了pdf但是,行内容组织得不好,他们是曲折的。帮我解决这个问题??

0 个答案:

没有答案