【问题标题】:DOMPDF, I cannot create two pdf at timeDOMPDF,我不能同时创建两个 pdf
【发布时间】:2013-12-11 05:40:36
【问题描述】:

当我尝试一次创建两个 pdf 时,它会抛出错误...

致命错误:未捕获的异常“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 行

代码如下:

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

请帮帮我..

提前谢谢...

【问题讨论】:

  • 您使用的是什么框架和库/插件/插件?通常,在重新使用之前重置 dompdf 变量是一个好主意。此外,该错误通常表明向 dompdf 提供了空内容,您确定在这两种情况下 load_view 方法都有效吗?
  • 我们正在使用codeigniter,谢谢您的回复...我已经解决了这个问题...我重新初始化了pdf库,然后它开始工作...这是代码:$ pdf = 新的 pdf(); $pdf->set_base_path($data['path']); $pdf->load_view('adm/invoice/si2i',$data); $pdf->渲染(); $pdf = 新的 pdf(); $pdf->set_base_path($data['path']); $pdf->load_view('adm/invoice/si2i',$data); $pdf->render();

标签: php pdf-generation dompdf


【解决方案1】:

我刚刚遇到了同样的问题。解决方案是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 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2015-06-21
    • 2020-05-24
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2014-04-17
    相关资源
    最近更新 更多