user1424904
user1424904

Reputation: 21

dompdf not rendering images from the server but is rendering from external source

I'm trying to figure this out for the last few days now and come up with nothing.

I have dompdf working on my server and its creating the pdf fine. The only issue is its not rending the images I send to it. I have DOMPDF_ENABLE_REMOTE set to TRUE, tmp folder is writable and get_file_contents is turned on.

Now the sample that you get in the dompdf folder renders the remote images fine it just seems to be images file from my server that's causing the issue.

I've tried absolute and relative urls.

I'm running this through codeigniter, and its the beta version 0.6.0.

This is my helper:

   function create_pdf($html, $filename, $stream=TRUE) 
   {
    require_once("dompdf/dompdf_config.inc.php");

    spl_autoload_register('DOMPDF_autoload');

    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    if ($stream) {
        $dompdf->stream($filename.".pdf");
    } else {
        write_file("./pdf_written_files/$filename.pdf", $dompdf->output());
    }
}

My controller function:

function pdf($id)
{
    if($id !== NULL)
    {
        $this->load->helper(array('create_pdf','text'));

        $result = $this->product_model->order_by('order')->get_by(array('id' => $id))? : NULL;
        $collection = $this->collection_model->my_collection($result->id);
        $range = $this->range_model->my_range($result->id);
        $result->collection = $collection;
        $result->range = $range;
        $this->_data['content'] = $result;
        $html = $this->load->view('created_pdf', $this->_data, TRUE);
        create_pdf($html, $result->title);
    }
    else
    {
        echo 'no input found';
    }
}

Upvotes: 2

Views: 9530

Answers (3)

Sumit Kumar Gupta
Sumit Kumar Gupta

Reputation: 2364

Add following lines

$dompdf = new DOMPDF();
$dompdf->set('isRemoteEnabled', true);
$dompdf->load_html($html);

if this is not working then change method from set to set_option

Upvotes: 0

Aboudramane ZARE
Aboudramane ZARE

Reputation: 1

I had the exact same problem, no images were displaying for me - background images and inline ones. I had to set DOMPDF_ENABLE_REMOTE to true in your config dompdf_config.inc.php

Just note the security risk if you have this enabled along with DOMPDF_ENABLE_PHP.

Upvotes: 0

Bharata
Bharata

Reputation: 747

Your image link must use the relative path from your web folder. Example, if your web folder is in /var/www/html/myweb and your image in your CI folder is in assets/images (in the same level as application folder), you just write the relative path : assets/images/imgname.jpg.

Upvotes: 4

Related Questions