2

我使用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 它会返回该错误

感谢

4

2 回答 2

6

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

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

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;
 }
于 2014-03-17T15:28:22.817 回答
1

在这种情况下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>
于 2015-05-23T09:31:57.727 回答