Search code examples
phphtmlcodeigniterhtml2pdf

could not load image in html2pdf in codeigniter


I am trying to create a pdf file from html in my codeigniter project. The html file contains an image but it will not load in the pdf. I am using html2pdf library and here is my code.

example.php :

<img src="<?php echo base_url()?>assets/images/logo.jpg" alt="BulkSMS">

I am pasting only the <img> tag here, because it is a large file.

and here is my controller function

public function htmlToPdf($data) {

    $this->html2pdf->folder(PURCHASE_INVOICE_PATH);
    $fileName = $data['invoiceNumber'].'.pdf';
    $this->html2pdf->filename($fileName);

    $this->html2pdf->paper('a4', 'portrait');

    $content = $this->load->view('templates/example', '', true);
    //Load html view
    $this->html2pdf->html($content);
    $this->html2pdf->create('save');  
    return $fileName;
}

I tried to change path of image to full path and type of image from png to jpg. But still it not showing


Solution

  • This issue is happening becuase of CORS. Uncomment The following line from the dompdf_config.inc.php file located in application/libraries/dompdf folder.

    define("DOMPDF_ENABLE_REMOTE", true);