当pdf文件保存到磁盘时,tcpdf库不在循环内打印数据

时间:2015-04-15 20:05:48

标签: php pdf tcpdf

以下是我创建pdf的代码。当pdf保存到磁盘时,循环内的数据不会显示在pdf中 只需在浏览器中显示pdf或下载它即可。但是当我将pdf保存到磁盘时出现问题告诉我如何解决这个问题 在html函数中传递的writeHTML()时,这可能会出现问题。我的html连接是否有问题?

 $html = '
<h1>Castlenet Limited </h1><br>

<div style="line-height:10px;">
<p >8 Eclipse Lane</p><br><br>
<p >Whitby</p><br>
<p >04 234 6336</p><br><br><br>
</div>
<div style="line-height:10px;">
<p>CUST_NAME : '.$metadata['customer']['cust_ref'].'</p><br>
<p>CUST_COMPANY : '.$metadata['customer']['cust_company'].'</p><br>
<p>CUST_EMAIL: '.$metadata['customer']['cust_email'].'</p><br>
<p>CUST_PHONE : '.$metadata['customer']['cust_phone'].'</p><br>
</div>';
$pdf->writeHTML($html, true, false, false, false, '');

foreach ($metadata['websites'] as $data)
{
        $html = '<b>Website :'. $data['web_title'].'      '. $data['web_url'].' </b><br><b>Storage :'. $data['stor_type'].' </b><br><table border="1" style="width:100%"><tr><th style="width:40%;">Date</th><th style="width:20%;">size</th><td>File</td></tr>';

        $pdf->writeHTML($html, true, false, false, false, '');

        foreach ($data['files'] as $file)
        {
            //$html .= '<tr><td><pre>'.print_r($file).'</td></tr>';
            $html = '<tr><td></td>
                            <td>'. $file["size"].'</td>
                            <td>'. $file["path"].'</td>
                        </tr>
                        ';
            $pdf->writeHTML($html, true, false, false, false, '');


        }
        $html = '</table><br><br>';
        $pdf->writeHTML($html, true, false, false, false, '');

  } 


// Print text using writeHTMLCell()
//$pdf->writeHTML($html, true, false, false, false, '');
//$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);   

// ---------------------------------------------------------    
//$pdf->lastPage();
// Close and output PDF document

//This method has several options, check the source code documentation for more information.
$pdf->Output($_SERVER['DOCUMENT_ROOT'].'projects/reports/assets/reports/example_001.pdf', 'F');    

//============================================================+
// END OF FILE
//============================================================+
}

块引用

1 个答案:

答案 0 :(得分:1)

  

得到了解决方案!要附加文件,您必须在{中添加'E'而不是'F'   $this->Output('example.pdf','E');并且你不必再次调用writeHTML()函数在循环结束后调用它一次。