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

使用dompdf库生成pdf文件,而我打开它显示的pdf文件无法加载内容错误。 我设置了下面给出的渲染器路径和渲染器库。</ p>

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

展开原文

原文

Using dompdf library generate the pdf file, while i opened that pdf file it shows failed to load content error. I set renderer path and renderer library given below.

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

php
doubiao7267
doubiao7267 在文本编辑器中打开文件,在文件正文中查找任何前导或尾随空格字符,BOM标题或明文PHP错误消息....并学习为自己做一些基本的调试
5 年多之前 回复

2个回答



试试这个</ p>

  $ rendererName = PHPExcel_Settings :: PDF_RENDERER_DOMPDF; 
$ rendererLibrary ='dompdf.php';
$ rendererLibraryPath = dirname(__ FILE__)。 'libs / classes / dompdf'。 $ rendererLibrary;
</ code> </ pre>

根据此</ p>

  $ file =“path_to_file”纠正您的PHP; 
$ 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;
</ code> </ pre>
</ div>

展开原文

原文

Try this

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

Correct your PHP according to this

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

drlnsli18864734
drlnsli18864734 好的,谢谢你的帮助。
5 年多之前 回复
drd94483
drd94483 在这种情况下,我不能帮助你
5 年多之前 回复
doupa2871
doupa2871 我改变了上面给出的内容的PHP文件,但我仍然面临同样的问题。
5 年多之前 回复
dongyun6229
dongyun6229 您可以尝试更改PHP
5 年多之前 回复
duan19850312
duan19850312 我也试过这个,但我仍面临同样的问题。
5 年多之前 回复



今天刚出现类似错误,但PHPExcel没有。 </ p>

我不得不用PHP填充PDF并在之后显示,但我总是从Chrome中收到“无法加载PDF文档”错误。 </ p>

我不知道是不是同样的问题,但在我的情况下,PHP报告了通知和警告错误,没什么太重要,但正因为如此,PDF无法解决 载入。 隐藏错误解决了我的问题!</ p>

TL; DR:在PHP文件的顶部尝试 error_reporting(E_STRICT); </ code>(快速和脏)或 在读取文件之前退出; </ code>,这样你就可以看到错误并修复它们。</ p>
</ div>

展开原文

原文

Just had a similar error today but not with PHPExcel.

I had to populate a PDF with PHP and show it after, but I was always getting a "Failed to load PDF document" error from Chrome.

I don't know if it was the same problem, but in my case, PHP was reporting Notice and Warning errors, nothing too important, but because of that, the PDF was not able to load. Hiding the error solved my problem!

TL;DR : Try error_reporting(E_STRICT); on top of your PHP file (quick and dirty) or exit; before reading the file so you can see the errors and fix them.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐