错误:GetFilter无法打开对象流,因为过滤器

时间:2018-04-12 09:18:15

标签: php pdf codeigniter-3 fpdf

使用FPDM库在可编辑PDF中绑定数据时出现此错误。

我想将此数据绑定到PDF。 PDF完全没有问题。 此代码仅为Array的第一个实例创建PDF。

当我将此代码组合到Codeigniter时,我收到错误。

你可以看到我的代码如下所示,并建议解决方案。

代码

<?php

/***************************
  Sample using a PHP array
****************************/

require('fpdm.php');



    $fields[0] = array( 'app_no'    => '43922230',
         'name1' => 'pravinkumar R',
         'name2'    => 'ramabhai patel',
         'address1'   => '25127 samani society',
         'branch_code'   => '300047',
         'area'   => 'chansma',
         'city'   => 'chansma',
         'pin'   => '384220',
         'email'   => '0',
         'phone'   => '9033381560',
         'pan'   => 'AEOEPP0147F',
         'pan2'   => 'AEOEPP0147F',
         'client_id1' => 'IN30154945999461',
         'NSDL'    => '1',
         'CDSL'   => '0',
         'personal'   => '1',
         'huf'    => '0',
         'date'   => '12-01-2018',
         'bank_name2'    => 'AXIS BANK,CHANSMA',
         'bank_acco_no1' => '50100020583815',
         'amount_block2'    => '13150',
         'client_id2'   => 'IN30154945999461',
         'app_no2'   => '43922230',
         'bank_no3'    => '50100020583815',
         'bank_name' => 'AXIS BANK,CHANSMA',
         'amount_words'    => 'thirteen thousand one hundred fifty only',
         'amount_blocked'   => '13150',
         'share'   => '50',


         'amount_block3'    => '13150',
         'share2' => '50',
         'email2'    => ' ',
         'phone2'   => '9033381560',
         'client_name'   => 'ramabhai patel',
         'app_no3'    => '43922230',
         'bank_name3' => 'AXIS BANK,CHANSMA',
         'name2'    => 'ramabhai patel',
         'bank_acco_no2'   => '50100020583815',
         'name3'   => 'name3');


    $fields[1] = array( 'app_no'    => '43922230',
         'name1' => 'pravinkumar R',
         'name2'    => 'ramabhai patel',
         'address1'   => '25127 samani society',
         'branch_code'   => '300047',
         'area'   => 'chansma',
         'city'   => 'chansma',
         'pin'   => '384220',
         'email'   => '0',
         'phone'   => '9033381560',
         'pan'   => 'AEOEPP0147F',
         'pan2'   => 'AEOEPP0147F',
         'client_id1' => 'IN30154945999461',
         'NSDL'    => '1',
         'CDSL'   => '0',
         'personal'   => '1',
         'huf'    => '0',
         'date'   => '12-01-2018',
         'bank_name2'    => 'AXIS BANK,CHANSMA',
         'bank_acco_no1' => '50100020583815',
         'amount_block2'    => '13150',
         'client_id2'   => 'IN30154945999461',
         'app_no2'   => '43922230',
         'bank_no3'    => '50100020583815',
         'bank_name' => 'AXIS BANK,CHANSMA',
         'amount_words'    => 'thirteen thousand one hundred fifty only',
         'amount_blocked'   => '13150',
         'share'   => '50',


         'amount_block3'    => '13150',
         'share2' => '50',
         'email2'    => ' ',
         'phone2'   => '9033381560',
         'client_name'   => 'ramabhai patel',
         'app_no3'    => '43922230',
         'bank_name3' => 'AXIS BANK,CHANSMA',
         'name2'    => 'ramabhai patel',
         'bank_acco_no2'   => '50100020583815',
         'name3'   => 'name3');

    //print_r($fields);
    $dir = "client_pdf/";
    $i=1;
    foreach($fields as $key => $val){

        $pdfName = "sample_".$i.".pdf";
        //echo $pdfName."<br>";
        $pdf = new FPDM('pdf/newgen.pdf');
        $pdf->Load($val, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
        $pdf->Merge();
        $pdf->Output('group_pdf/pdf.pdf','F');
        $i++;
    }

    ?>

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,在一个foreach周期中,只有第一次迭代有效。
我发现,因为在FPDM类构造函数中,过滤器是通过require_once语句加载的,因此在第一次迭代之后就不再加载它们。

我的解决方案是在循环之前仅实例化FPDM类。
在周期内仅Load()Merge()Output()

除非您需要更改模板,否则无需多次实例化,Load()方法将替换所有字段,然后您可以安全Merge()
它对我有用。

$pdf = new FPDM('pdf/newgen.pdf');
foreach($fields as $key => $val){
    $pdfName = "sample_".$i.".pdf";
    $pdf->Load($val, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
    $pdf->Merge();
    $pdf->Output('group_pdf/pdf.pdf','F');
    $i++;
}