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

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

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

in

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

这是亩代码:

在 Controller 中:
   $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

并在其他任何 View 文件中使用具有相同图像路径的相同图像标签,但是如果使用HTML2PDF,它将返回该错误

谢谢

最佳答案

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

通过将服务器文档根添加到图像源中,在 html2pdf.class.php 文件中的第5602行。

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

关于php - Yii HTML2PDF(ePdf)不可能的充电器l'image/images/big-logo.png,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22449972/

10-13 02:26