DOMPDF渲染PNG文件时遇到了一些严重的令人费解的问题。
在Windows IIS服务器上根据Github页面使用最新版本的DOMPDF。
我有一个双重问题:
这是一个截图来解释:
现在,如果我用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
有谁知道这可能导致这些看似奇怪的问题?
答案 0 :(得分:0)
好的,原来是因为我们的服务器上没有安装ImageMagick。在尝试生成包含PNG文件的PDF之前,DomPDF应该检查它的存在吗?
仅供记录,以下是我在IIS上安装ImageMagick所需采取的步骤:
ImageMagick-6.6.2-10-Q16-windows-dll
。php_imagick_nts.dll
)添加到this link的PHP扩展目录。extension=php_imagick_nts.dll
添加到php.ini cacls c:\windows\temp /E /C /G iusr_SERVERNAME:R
值得注意的是,最后的声明在工作安装中可能被认为是不安全的。您可以在配置设置中更改imagick临时目录,但我个人无法使其正常工作。