2015-03-02 80 views
0

使用dompdf庫生成pdf文件,而我打開該pdf文件時,它顯示未能加載內容錯誤。我設置了下面給出的渲染器路徑和渲染器庫。使用dompdf庫在PHPExcel中生成pdf文件

$ rendererName = PHPExcel_Settings :: PDF_RENDERER_DOMPDF; $ rendererLibrary ='dompdf.php'; $ rendererLibraryPath = name(FILE)。'/ ../dompdf/libraries/dompdf /'.$ rendererLibrary;

+1

在文本編輯器中打開文件,並在文件正文中查找任何前導或尾隨空白字符,BOM標題或明文PHP錯誤消息....並學習爲自己做一些基本的調試。 – 2015-03-02 08:35:25

回答

0

根據本

$file = "path_to_file"; 
$fp = fopen($file, "r") ; 

header("Cache-Control: maxage=1"); 
header("Pragma: public"); 
header("Content-type: application/pdf"); 
header("Content-Disposition: inline; filename=".$myFileName.""); 
header("Content-Description: PHP Generated Data"); 
header("Content-Transfer-Encoding: binary"); 
header('Content-Length:' . filesize($file)); 
ob_clean(); 
flush(); 
while (!feof($fp)) { 
    $buff = fread($fp, 1024); 
    print $buff; 
} 
exit; 
+0

嘗試在這之上,但仍然面臨着同樣的問題。 – 2015-03-02 12:35:00

+0

您可以嘗試更改PHP – Lafontein 2015-03-02 12:38:20

+0

我改變了以上給出的內容的PHP文件,但仍然面臨同樣的問題。 – 2015-03-02 13:08:57

0

試試這個

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; 
$rendererLibrary = 'dompdf.php'; 
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary; 

糾正你的PHP剛剛有了一個類似的錯誤,但今天不是PHPExcel。

我不得不使用PHP填充PDF並顯示它,但我總是從Chrome中獲得「無法加載PDF文檔」的錯誤。

我不知道它是否是同樣的問題,但在我的情況下,PHP報告了通知和警告錯誤,沒有太重要的,但正因爲如此,PDF無法加載。隱藏錯誤解決了我的問題!

TL; DR:在讀取文件之前,請在您的PHP文件(快速和髒的)或exit;的頂部嘗試error_reporting(E_STRICT);,以便您可以查看錯誤並修復它們。