1
我已經實現創建PDF,如何在cakephp循環中創建pdf文件?
http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and-tcpdf
但在我的邏輯, 有一個鏈接「printAll」,然後在循環,我必須生成發票的PDF很多很多次。 那麼可以使用循環在一個函數中創建多個PDF文件?
直到現在我已經把邏輯放在ctp文件中,並在foreach循環中寫入邏輯,但仍然只生成第一條記錄的pdf。
我該怎麼做?有沒有其他方法可以做到這一點?
那麼請任何人都可以幫助我?
在此先感謝..
在generate_invoice.ctp<?php
App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF();
$textfont = 'freesans';
$tcpdf->SetAutoPageBreak(false);
$tcpdf->xheadercolor = array(255,255,255);
$tcpdf->AddPage();
$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',10);
$total_records = 0;
foreach($POdata as $order)
{
$po = $order['Orderproduct']['id'];
$total_records = $total_records + 1;
}
if($total_records == 1)
{
$html = <<<EOD
$po; //and other html
EOD;
$tcpdf->writeHTMLCell(0, 0, '', '', $html,'', 1, 0, true, '', true);
echo $tcpdf->Output('filename.pdf', 'D');
}
else if($total_records > 1)
{
foreach($POdata as $order)
{
$po = $order['Orderproduct']['id'];
$total_records = $total_records + 1;
$html = <<<EOD
$po; //and other html
EOD;
$tcpdf->writeHTMLCell(0, 0, '', '', $html,'', 1, 0, true, '', true);
$filename = "PO".$poid.".pdf";
echo $tcpdf->Output($filename, 'D');
}
}
和數據控制器文件查看文件正確得到$ POdata。 這麼新,你可以幫我。
剛剛晉級前8行我的代碼,並粘貼「如果」和「其他」塊,就在'$ html'聲明之上,它已完成...... – Dolly 2012-02-22 06:03:42