dompdf不是从服务器渲染图像,而是从外部源渲染图像 [英] dompdf not rendering images from the server but is rendering from external source

查看:62
本文介绍了dompdf不是从服务器渲染图像,而是从外部源渲染图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在想在最近几天里解决这个问题,什么也没想.

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

我有dompdf在我的服务器上工作,并且创建pdf很好.唯一的问题是它不保存我发送给它的图像.我已将DOMPDF_ENABLE_REMOTE设置为TRUE,tmp文件夹可写,并且get_file_contents已打开.

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.

现在,在dompdf文件夹中获得的示例可以很好地渲染远程图像,似乎只是导致问题的服务器中的图像文件.

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.

我尝试了绝对和相对URL.

I've tried absolute and relative urls.

我正在通过codeigniter及其beta版本0.6.0来运行它.

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

这是我的助手:

   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());
    }
}

我的控制器功能:

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

推荐答案

您的图片链接必须使用Web文件夹中的相对路径.例如,如果您的Web文件夹位于/var/www/html/myweb中,并且CI文件夹中的图像位于资产/图像中(与应用程序文件夹处于同一级别),则只需编写相对路径:assets/images/imgname .jpg.

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.

这篇关于dompdf不是从服务器渲染图像,而是从外部源渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆