DOMPDF,我一次无法创建两个pdf

问题描述:

当我尝试一次创建两个pdf时,会引发错误...

When i try to create two pdf at a time it's throwing errors...

致命错误:消息为"No"的未捕获异常"DOMPDF_Exception" 找到块级父级.不好.'在 C:\ wamp \ www \ si2i \ application \ libraries \ dompdf \ include \ inline_positioner.cls.php 在第38行(!)上DOMPDF_Exception:找不到块级父级.不是 好的.在 C:\ wamp \ www \ si2i \ application \ libraries \ dompdf \ include \ inline_positioner.cls.php 在第38行

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);

请帮帮我..

预先感谢...

我只是遇到了同样的问题.解决的办法是将codeigniter pdf库$ this-> load-> library('pdf');创建一个每次都会被调用的DOMPDF实例,但是该类无法正确地对其自身进行清理,因此,如果您需要生成多个pdf,则会崩溃.

I just faced the same problem. The solution is that the codeigniter pdf library $this->load->library('pdf'); creates a single DOMPDF instance that is called every time, however the class doesn't clean up after itself properly, so crashes if you need to generate more than one pdf.

解决方案是根据需要手动实例化DOMPDF类.不要使用codeigniter pdf包装器.

The solution is to manually instantiate the DOMPDF class as you need it. Don't use the codeigniter pdf wrapper.

//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 );