douju6651 2016-11-25 09:58
浏览 42

在EZPDF中一次生成多个PDF

I don't know why its not working. I've used while loop to generate multiple pdfs with ezpdf class, and only 1 pdf is creating. I also tried 'for loop' but is still the same . What should i do to achieve more than one pdf?

include ('class.ezpdf.php');
$limit = 1;
while($limit < 5){
  $colw = array(      80 ,    40,   220,    80,     40  );//column widths
 $rows = array(
     array('company','size','desc','cost','instock'),
     array("WD", "80GB","WD800AAJS SATA2 7200rpm 8mb"        ,"$36.90","Y"),

 );

 //x is 0-600, y is 0-780 (origin is at bottom left corner)
 $pdf =& new Cezpdf('LETTER');

 $total=0;
 $curr_x=80;
 $curr_y=600;
 foreach($rows as $r)
 {
     $xoffset = $curr_x;
     foreach($r as $i=>$data)
     {
         $pdf->setColor(0/255,0/255,0/255);
         $pdf->addText( $xoffset, $curr_y , 10, $data );
         $xoffset+=$colw[$i];
     }
     $curr_y-=20;
 }
define('MY_FILENAME', 'testDoc'.$limit.'.pdf');
$pdfcode = $pdf->ezOutput();
$fp = fopen(MY_FILENAME, 'wb');
fwrite($fp, $pdfcode);
fclose($fp); 

}
  • 写回答

1条回答 默认 最新

  • dongwen9051 2017-02-28 14:14
    关注

    Maybe I think your problem occurs because you try to set a constant value with define() in a loop. I tested it and the define-variable (MY_FILENAME) had always the same value inside a loop. It seems that PHP doesn't set defined variables again.

    Your solution woul'd be to replace your define variable (MY_FILENAME) with a regular variable like this...

    for ($i = 0; $i < 10; $i++)
    {
        $myPDFFile = "PDF" . $i . ".pdf";
    
        $pdf = new Cezpdf('A4');    // create CezPDF-object
    
        // write content to PDF-file
    
        $pdfCode = $pdf->output();  // content of PDF to variable
    
        $file = fopen($myPDFFile, "wb");
        fwrite($file, $pdfCode);
        fclose($file);
    }
    

    instead of

    for ($i = 0; $i < 10; $i++)
    {
        define(MY_FILENAME, "testDoc" . $i . ".pdf");
        ...
    }
    

    I hope this woul'd work for you.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)