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