Osa*_*awe 2 php html-to-pdf yii yii-extensions
我使用Yii框架,我使用 EYiiPdf扩展.
我必须在Pdf输出文件中查看图像但我收到此错误:
ERREUR n°6 : Impossible de charger l'image /images/big-logo.png
in
/protected/vendor/html2pdf/html2pdf.class.php(1319)
Run Code Online (Sandbox Code Playgroud)
这是mu代码:
在控制器中:
$html2pdf = Yii::app()->ePdf->HTML2PDF();
$html2pdf->WriteHTML($this->renderPartial('index', true));
$html2pdf->Output();
Run Code Online (Sandbox Code Playgroud)
这是视图中的图像标签
<img src="/images/big-logo.png" alt="logo" style="width: 190px; height: 70px">
Run Code Online (Sandbox Code Playgroud)
图像文件夹和图像存在.
这是我的文件夹结构
images
js
css
protected
--->controoler
--->views
--------->pdf
------------->index.php
Run Code Online (Sandbox Code Playgroud)
以及在任何其他视图文件中使用相同图像路径的相同图像标记,但如果使用HTML2PDF则返回该错误
谢谢
我解决了我的问题:
在第5602行的html2pdf.class.php文件中,将服务器Document Root添加到图像源.
protected function _tag_open_IMG($param)
{
$src = str_replace('&', '&', $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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6493 次 |
| 最近记录: |