2013-03-19 109 views
1

有與PNG文件DOMPDF的渲染一些嚴重的精神錯亂的問題,只顯示一個PNG。DOMPDF PNG輸出 - 多個PNG格式不正確的顏色

使用根據自己的Github的頁面DOMPDF的最新版本,在Windows IIS服務器上。


我有一個雙重的問題:

  1. PNG圖像與黑色背景和白色前景顯示,無論圖像
  2. 如果使用多個PNG圖像的顏色,所有網頁上的圖像顯示爲第一個圖像,擠壓成不同的尺寸比

這裏有一個截圖來解釋:

現在

Banner

,如果我取代JPEG文件的圖像之一,它的工作原理:

jpeg

如果我改變第一PNG圖像渲染,它顯示是這樣的:

Barry


的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 

有誰知道什麼可能導致這些看似奇怪的問題?

+1

這是奇怪的。看起來像其中一個圖像正在解析它的alpha通道,這就是放置,雖然我不能說爲什麼。這可能是一個路徑問題,你可以從'unlink()'調用中看到有一些不完整的文件名。這些錯誤似乎是dompdf/cpdf的內部錯誤,但是您可以通過檢查由dompdf解析的HTML開始。調用'$ dompdf-> output_html();'在加載HTML後查看dompdf在內部使用的是什麼。你也可以在dompdf/www/setup.php上查看設置頁面,看看是否有紅旗。 – BrianS 2013-03-20 02:39:11

回答

0

OK,這竟然是因爲ImageMagick的不是我們的服務器上安裝。在嘗試生成包含PNG文件的PDF之前,DomPDF應該檢查它的存在嗎?

只是爲了記錄在案,這裏有我需要採取在IIS上安裝ImageMagick的步驟:

  • 卸載現有imagick設施和PHP
  • 擴展DLL從here安裝imagick ImageMagick-6.6.2-10-Q16-windows-dll
  • this link添加最新版本的線程安全(TS)或非線程安全(NTS)的dll,例如php_imagick_nts.dll,到PHP擴展目錄。
  • 添加extension=php_imagick_nts.dll到PHP。INI
  • 以下運行cmd命令到IIS權限添加到臨時目錄:cacls c:\windows\temp /E /C /G iusr_SERVERNAME:R

值得一提的是,最後的聲明可能被認爲是對工作的設施不安全。您可以在配置設置中更改imagick臨時目錄,但是我個人無法使其工作。

+0

除非您啓用了ImageMagick PHP擴展,否則dompdf將不會使用ImageMagick。如果您尚未安裝ImageMagick,請不要啓用ImageMagick擴展。 – BrianS 2013-03-21 15:12:01

+0

另外,根本不需要ImageMagick。 dompdf能夠用GD擴展來完成它的工作。提供ImageMagick支持是因爲它可以提高圖像處理的性能。 – BrianS 2013-03-21 15:15:26