2013-11-26 47 views
0

創建兩個PDF時,我嘗試在同一時間它拋出錯誤創建兩個PDF ...DOMPDF,我不能在時間

Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No block-level parent found. Not good.' in C:\wamp\www\si2i\application\libraries\dompdf\include\inline_positioner.cls.php on line 38 (!) DOMPDF_Exception: No block-level parent found. Not good. in C:\wamp\www\si2i\application\libraries\dompdf\include\inline_positioner.cls.php on line 38

這裏是代碼:

$this->load->library('pdf'); 
        $this->pdf->set_base_path($data['path']); 
        $this->pdf->load_view('adm/invoice/si2i',$data); 
        $this->pdf->render(); 
        $output = $this->pdf->output(); 
        file_put_contents("uploads/invoice/invoice_".$invoice_file_name.".pdf", $output); 

$this->load->library('pdf'); 
        $this->pdf->set_base_path($data['path']); 
        $this->pdf->load_view('adm/invoice/si2i',$data); 
        $this->pdf->render(); 
        $output = $this->pdf->output(); 
        file_put_contents("uploads/invoice/invoice_".$invoice_file_name.".pdf", $output); 

請幫我出..

在此先感謝...

+0

您使用的是什麼框架和庫/插件/附加組件?通常在重新使用之前重置dompdf變量是一個好主意。此外,該錯誤通常表明null內容被送到dompdf,你確定在這兩種情況下load_view方法正在工作嗎? – BrianS

+0

我們正在使用codeigniter,感謝您的回覆......我已經解決了這個問題....我已經重新初始化了pdf庫,然後它開始工作......下面是代碼:$ pdf = new pdf(); $ pdf-> set_base_path($ data ['path']); $ pdf-> load_view('adm/invoice/si2i',$ data); $ pdf-> render(); $ pdf = new pdf(); $ pdf-> set_base_path($ data ['path']); $ pdf-> load_view('adm/invoice/si2i',$ data); $ pdf-> render(); – sangeethulugonda

回答

5

我剛剛面臨同樣的問題。解決方法是codeigniter pdf庫$ this-> load-> library('pdf');創建一個每次都調用的單個DOMPDF實例,但是該類沒有正確清理後,如果需要生成多個pdf,則會崩潰。

解決方案是根據需要手動實例化DOMPDF類。不要使用codeigniter pdf包裝器。

//require at the top of our script 
require_once(APPPATH .'libraries/dompdf/dompdf_config.inc.php'); 

//get the html first (base dompdf cant do the combined load/render) 
$view = $this->load->view("viewname", $viewData, true); 
//create a new dompdf instance (this is the crucial step) 
$this->pdf = new DOMPDF(); 
//render and output our pdf 
$this->pdf->load_html($view); 
$this->pdf->render(); 
$pdf = $this->pdf->output(array("compress" => 0)); 
file_put_contents("some/file/path.pdf", $pdf);