DOMPDF, I cannot create two pdf at time
Asked Answered
F

2

1

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

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

here is the code:

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

Please help me out..

Thanks in advance...

Farflung answered 26/11, 2013 at 7:30 Comment(2)
What framework and library/plug-in/add-on are you using? Generally it's a good idea to reset the dompdf variable before re-use. Also, that error generally indicates that null content was fed to dompdf, are you sure in both instances the load_view method is working?Quagga
We are using codeigniter, Thank you for the reply... I have resolved the issue.... I have reinitialize the pdf library, then it started working... Here is the code:$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();Farflung
P
7

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.

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 );
Paulo answered 9/5, 2014 at 1:32 Comment(0)
C
0

I faced this issue with CodeIgniter 3 when I was trying to generate the pdfs in a loop. The issue was due to loading the pdf library multiple times and not clearing the existing instance. To avoid this - I have created new instance of PDF each time.

require_once APPPATH.'third_party/dompdf/autoload.inc.php';
use Dompdf\Dompdf;

class Index extends CI_Controller {

    public function gencert() {
       $nurseids = $this->nurse_model->getNurseIdsForCert();
       foreach($nurseids as $nid){
         //print_r($nid);
         $this->nursecertificate($nid->nurseid);
       } 
    }
    
    private function nursecertificate($nurseid){
       // Load pdf library
       //$this->load->library('pdf');
       $this->pdf = new DOMPDF();
    
       // Load HTML content
       $this->pdf->loadHtml($html, []);
       ...
Coalfish answered 21/6, 2023 at 3:24 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.