如何在cakephp中循环创建pdf文件? [英] How to create pdf file in loop in cakephp?

查看:150
本文介绍了如何在cakephp中循环创建pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实施了pdf创建,

I have implemented pdf creation,

http://bakery.cakephp.org/articles/kalileo/2010/06/08/creating-pdf-files-with-cakephp-and -tcpdf

但在我的逻辑,
有一个链接printAll然后在循环中我必须生成发票pdf许多次。
所以是可能使用循环在一个函数中创建多个pdf文件?

but in my logic, there is a link "printAll" then in loop i have to generate invoice pdf many number of times. so is that possible to create multiple pdf files in one function using loop?

到现在我把逻辑放在ctp文件和写逻辑在foreach循环,仍然只有第一个记录的pdf生成。

till now i have put logic in ctp file and write logic in foreach loop but still only first's record's pdf is generated.

我该如何做?有没有其他方法这样做?

how can I do that? Is there any other way to do this?

因此任何人都可以帮助我。

so please anyone can help me??

..

in generate_invoice.ctp

in 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。

and data from controller file to view file is correctly get in $POdata. so new can you please help me.

推荐答案

是的,我们可以这样做

使用foreach()中继器对象,并基于该数据生成PDF并存储在某个位置,您可以使每个文件的显示路径数组

use foreach() to repeater objects and based on that data generate the PDF and store at some location and you can make array of the display path of each file

将此数组传递给视图的对象,您可以在视图文件中使用它。

pass this array to the object of the view and you can use that in the view file you can also set as download link

感谢

这篇关于如何在cakephp中循环创建pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆