【问题标题】:Yii HTML2PDF (ePdf) Impossible de charger l'image /images/big-logo.pngYii HTML2PDF (ePdf) 不可能的 de 充电器 l'image /images/big-logo.png
【发布时间】:2014-03-17 08:49:14
【问题描述】:

我使用 Yii 框架,我使用 EYiiPdf 扩展。

我必须在 Pdf 输出文件中查看图像,但出现此错误:

ERREUR n°6 : Impossible de charger l'image /images/big-logo.png

in

/protected/vendor/html2pdf/html2pdf.class.php(1319)

这是mu代码:

在控制器中:

   $html2pdf = Yii::app()->ePdf->HTML2PDF();
   $html2pdf->WriteHTML($this->renderPartial('index', true));
   $html2pdf->Output();

这是视图中的图像标签

<img src="/images/big-logo.png" alt="logo" style="width: 190px; height: 70px"> 

图像文件夹和图像存在。

这是我的文件夹结构

images
js
css
protected
--->controoler
--->views
--------->pdf
------------->index.php

以及在任何其他视图文件中具有相同图像路径的相同图像标记,但如果使用 HTML2PDF,则会返回该错误

谢谢

【问题讨论】:

    标签: php yii yii-extensions html-to-pdf


    【解决方案1】:

    我通过以下方式解决了我的问题:

    html2pdf.class.php 文件的第 5602 行。通过将服务器 Document Root 添加到图像源。

    protected function _tag_open_IMG($param)
    {
        $src           = str_replace('&amp;', '&', $param['src']);
        $documentRoot  = $_SERVER['DOCUMENT_ROOT']; // get server document root             
        $src           = $documentRoot. '/' . $src; //aapend server document root to the image soure
        $this->parsingCss->save();
        $this->parsingCss->value['width']    = 0;
        $this->parsingCss->value['height']    = 0;
        $this->parsingCss->value['border']    = array('type' => 'none', 'width' => 0, 'color' => array(0, 0, 0));
        $this->parsingCss->value['background'] = array('color' => null, 'image' => null, 'position' => null, 'repeat' => null);
        $this->parsingCss->analyse('img', $param);
        $this->parsingCss->setPosition();
        $this->parsingCss->fontSet();
        $res = $this->_drawImage($src, isset($param['sub_li']));
        if (!$res) return $res;
        $this->parsingCss->load();
        $this->parsingCss->fontSet();
        $this->_maxE++;
        return true;
     }
    

    【讨论】:

    • 解决了我的问题,是由于“allow_url_fopen”必须在 php.ini 中设置为“on”
    【解决方案2】:

    在这种情况下html2pdf.class.php只取图片路径而不是url,其实你不需要更改库代码,只需要...

    <img src="<?=Yii::getPathOfAlias('webroot').'/images/big-logo.png'?>">
    
    for background image...
    
    <div style="background-image: url(<?=Yii::getPathOfAlias('webroot').'/images/big-logo.png'?>)">
    
    ...
    </div>
    

    【讨论】:

      猜你喜欢
      • 2019-11-29
      • 2021-12-01
      • 2021-06-03
      • 2020-09-22
      • 2022-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      相关资源
      最近更新 更多