2

私はYii フレームワークを使用しており、 EYiiPdf拡張機能を使用して います。

Pdf出力ファイルで画像を表示する必要がありますが、次のエラーが発生しました。

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

in

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

これはミューコードです:

コントローラーで:

   $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

私は次の方法で問題を解決しました:

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;
 }
于 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 に答える