Question

Im using Yii framework, and Im using EYiiPdf extension.

I have to view an image in Pdf output file but I got this Error:

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

in

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

this is mu code :

in controller:

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

and this the image tag in view

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

the image folder and image exist.

this is my folder structure

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

and the same image tag with same image path working in any other view file but if use the HTML2PDF it return that error

Thank

Was it helpful?

Solution

I solved my problem by:

in html2pdf.class.php file at line 5602. by adding the server Document Root to image source.

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

OTHER TIPS

In this case html2pdf.class.php just take the image path instead of url, actually you dont need to change the library code, just need...

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top