生成PDF文件后如何清除内容?

时间:2018-03-22 05:24:21

标签: php mysql codeigniter dompdf

我有一个场景。

我有一个存储注册证书的Web应用程序(用CodeIgniter编码)。我所做的是我从数据库加载我的数据,然后使用foreach循环循环,然后获取每一行的内容,然后我将数据传递给我的视图。然后我使用dompdf库在其文件夹/目录中的每个商店生成PDF证书,其名称与行的id相同。

问题是,当循环完成时,目录会正确创建,但证书中的内容具有相同的数据,即同一行的数据。

我附上了我的代码,请在我错的地方帮忙,为什么所有内容都有相同的数据。

foreach ($business_info as $value) {

     ob_start();

       $business_id = $value->business_id;

         $data['businessowners'] = $this->this_business->this_businessowners($business_id);
         $data['certificate_data'] = $this->this_business->this_print_certificate($business_id);
         $data['account_owners'] = $this->this_business->this_accountowners($business_id);
         $data['is_all_partners'] = $this->db->query("select * from check_bank_operator($business_id)")->row();


         $html=$this->load->view('certificate', $data,true);

        //$folder = FCPATH . 'mfumo/data/certificates/'.$business_id;


         $folder = FCPATH . 'mfumo/data/docs/business/'.$business_id;
         if (!is_dir($folder))                             
         {
           mkdir($folder,0777, TRUE);
         }

        $save_path = 'mfumo/data/docs/business/'.$business_id .'/'.$business_id.'_cert.pdf';
        $system_root_file = FCPATH . $save_path;
        $this->load->helper('dompdf/pdf');
        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->set_paper('A4', 'portrait');
        $dompdf->render();
        $dompdf->get_canvas()->get_cpdf()->setEncryption('', 'n.*7&4%i:[}', array('print'));
        $output = $dompdf->output();
        $data = file_put_contents($system_root_file, $output);
        ob_clean()



 }

1 个答案:

答案 0 :(得分:1)

foreach($ business_info as $ value){

   $business_id = $value->business_id;

     $data['businessowners'] = $this->this_business->this_businessowners($business_id);
     $data['certificate_data'] = $this->this_business->this_print_certificate($business_id);
     $data['account_owners'] = $this->this_business->this_accountowners($business_id);
     $data['is_all_partners'] = $this->db->query("select * from check_bank_operator($business_id)")->row();


     $html=$this->load->view('certificate', $data,true);

    //$folder = FCPATH . 'mfumo/data/certificates/'.$business_id;


     $folder = FCPATH . 'mfumo/data/docs/business/'.$business_id;
     if (!is_dir($folder))                             
     {
       mkdir($folder,0777, TRUE);
     }

    $save_path = 'mfumo/data/docs/business/'.$business_id .'/'.$business_id.'_cert.pdf';
    $system_root_file = FCPATH . $save_path;
    $this->load->helper('dompdf/pdf');
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->set_paper('A4', 'portrait');
    $dompdf->render();
    $dompdf->get_canvas()->get_cpdf()->setEncryption('', 'n.*7&4%i:[}', array('print'));
    $output = $dompdf->output();
    $data = file_put_contents($system_root_file, $output);
    unset($dompdf);
    unset($data);

}