dompdf not rendering images from the server but is

2019-05-28 13:15发布

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';
    }
}

2条回答
smile是对你的礼貌
2楼-- · 2019-05-28 13:54

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.

查看更多
\"骚年 ilove
3楼-- · 2019-05-28 14:02

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.

查看更多
登录 后发表回答