【发布时间】:2012-02-21 11:59:51
【问题描述】:
我已经实现了 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 中正确获取。 这么新,你能帮帮我吗?
【问题讨论】:
标签: cakephp