簡體   English   中英

使用dompdf庫在PHPExcel中生成pdf文件

[英]Generate the pdf file in PHPExcel using dompdf library

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

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

嘗試這個

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

根據這個糾正你的PHP

$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;

今天剛出現了類似的錯誤,但PHPExcel卻沒有。

我不得不用PHP填充PDF並在之后顯示,但我總是從Chrome中收到“無法加載PDF文檔”錯誤。

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

TL; DR:嘗試error_reporting(E_STRICT); 在你的PHP文件之上(快速和臟)或exit; 在閱讀文件之前,您可以看到錯誤並修復它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM