1

DOMPDFによるPNGファイルのレンダリングに深刻な問題があります。

Windows IISサーバーで、Githubページに従って最新バージョンのDOMPDFを使用します。


私には2つの問題があります:

  1. PNG画像は、画像の色に関係なく、背景が黒、前景が白で表示されます。
  2. 複数のPNG画像を使用すると、ページ上のすべての画像が最初の画像として表示され、さまざまなサイズの比率に押しつぶされます

説明するスクリーンショットは次のとおりです。

バナー

ここで、画像の1つをJPEGファイルに置き換えると、次のように機能します。

jpeg

レンダリングする最初のPNG画像を変更すると、次のように表示されます。

バリー


私が使用しているHTMLは次のとおりです。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
        <title>test</title>

        <style type="text/css">

            *{
                color:'.$font.';
                font-family:Helvetica, Arial, Serif;
            }

            .i{font-style: italic;}
            .b{font-weight:bold;}

            h1, h2, h3, h4, h5, h6{display:inline;}
            h1{font-size:350%;}
            h3{font-size:275%;}
            h6{font-size:150%;}
            span{font-size:125%;}
            div{background-color:'.$bg.';}

        </style>
    </head>

    <body>

        <div align="center" style="margin-left:10px;margin-right:10px;padding:0px;">
            <br />
            <br />
            <br />
            <br />
            <img src="img/banner/'.$type.'/top.png" />
            <br />
            <br />
            <h1 class="b" style="color:'.$font.';">'.$type.' Certificate</h1>
            <br />
            <br />
            <h3 class="i" style="color:'.$font.';">'.$name.'</h3>
            <br />
            <br />
            <h6 style="color:'.$font.';">This certificate has been awarded to you for earning over '.$points.' points on the LEAP System.</h6>
            <br />
            <br />
            <img src="img/barry.png" />
            <br /><br />
            <img src="img/badge.png" />
            <br />
            <h6 class="i">' . 'Date Awarded: '.date("d-m-Y").'</h6>
            <br />
            <br />
            <span>Awarded by: '.$school.'</span>
            <br />
            <br />
            <img src="img/banner/'.$type.'/bottom.png" />
            <br />
            <br />
            <br />
            <br />
        </div>

    </body>
</html>

また、PDFの生成に使用しているPHPコードは次のとおりです。

public function save($data, $size, $orientation, $name, $type){
    $dompdf = new DOMPDF();
    $dompdf->set_paper($size, $orientation);
    $dompdf->load_html($data);
    $dompdf->render();
    $data = $dompdf->output();

    $filename = 'data/'.$type.'/'.$name.' - '.date("d-m-Y").'.pdf';
    return file_put_contents($filename, $data);
}

証明書を生成した後、次のログインを取得しますdompdf\lib\fonts\log.htm

52 7936.00 KB 1073.05 ms OFF
[__construct img/banner/Bronze/top.png][__construct img/barry.png][__construct img/badge.png][__construct img/banner/Bronze/bottom.png]get_min_max_width() auto auto;758.85850393701pt auto;773.85850393701pt auto;1010 121|757.5 90.75;get_min_max_width() auto auto;758.85850393701pt auto;773.85850393701pt auto;115 100|86.25 75;get_min_max_width() auto auto;758.85850393701pt auto;773.85850393701pt auto;187 60|140.25 45;[image:C:\Inetpub\wwwroot\frog\certificate_generator/img/banner/Bronze/top.png|1010|121|3]!!!png!!![addImagePng .png]
Warning: unlink(.png) [function.unlink]: No such file or directory in C:\Inetpub\wwwroot\frog\certificate_generator\dompdf\lib\class.pdf.php on line 4046
[image:C:\Inetpub\wwwroot\frog\certificate_generator/img/barry.png|115|100|3]!!!png!!!
Warning: unlink(.png) [function.unlink]: No such file or directory in C:\Inetpub\wwwroot\frog\certificate_generator\dompdf\lib\class.pdf.php on line 4046
[image:C:\Inetpub\wwwroot\frog\certificate_generator/img/badge.png|187|60|3]!!!png!!!
Warning: unlink(.png) [function.unlink]: No such file or directory in C:\Inetpub\wwwroot\frog\certificate_generator\dompdf\lib\class.pdf.php on line 4046
get_min_max_width() auto auto;758.85850393701pt auto;773.85850393701pt auto;1010 121|757.5 90.75;[image:C:\Inetpub\wwwroot\frog\certificate_generator/img/banner/Bronze/bottom.png|1010|121|3]!!!png!!!
Warning: unlink(.png) [function.unlink]: No such file or directory in C:\Inetpub\wwwroot\frog\certificate_generator\dompdf\lib\class.pdf.php on line 4046

これらの一見奇妙な問題を引き起こしている可能性があるものを誰かが知っていますか?

4

1 に答える 1

1

OK、これはサーバーに ImageMagick がインストールされていないことが原因であることが判明しました。DomPDF は、PNG ファイルを含む PDF を生成する前に、おそらくその存在を確認する必要がありますか?

念のため、IIS に ImageMagick をインストールするために必要な手順を次に示します。

  • 既存の imagick インストールと DLL 拡張機能を PHP からアンインストールする
  • ここImageMagick-6.6.2-10-Q16-windows-dllからimagick をインストールします。
  • スレッド セーフ (ts) または非スレッド セーフ (nts) dll の最新バージョンを、たとえば、このリンクphp_imagick_nts.dllから PHP 拡張ディレクトリに追加します。
  • extension=php_imagick_nts.dllphp.iniに追加
  • 次の cmd コマンドを実行して、IIS アクセス許可を一時ディレクトリに追加します。cacls c:\windows\temp /E /C /G iusr_SERVERNAME:R

最後のステートメントは、動作中のインストールでは安全でないと見なされる可能性があることに注意してください。imagick の一時ディレクトリは構成設定で変更できますが、個人的にはうまくいきませんでした。

于 2013-03-21T11:30:34.947 に答える