2012-02-21 57 views
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。 这么新,你可以帮我。

回答

0

是的,我们能做到这一点

使用的foreach()来Repeater对象,并基于该数据产生在一些位置上PDF和存储,并可以使每个文件

通的显示路径的阵列这个数组视图的对象,你可以使用,在视图文件,你还可以设置为下载链接

感谢

+1

刚刚晋级前8行我的代码,并粘贴“如果”和“其他”块,就在'$ html'声明之上,它已完成...... – Dolly 2012-02-22 06:03:42