【发布时间】:2017-03-06 18:31:44
【问题描述】:
我检查了大量资源,但我的问题无法解决。我试图通过包含 PHP File 来生成 PDF。但现在我陷入了“无法流式传输 pdf:标头已发送”错误。我还压缩了我的代码并删除了空格。 这是我的代码。
<?php
//ob_start();
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$return = include 'download_pdf.php';
$return = stripslashes($return);
$dompdf->loadHtml($return);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
//$dompdf->stream();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codex",array("Attachment"=>0));
?>
【问题讨论】:
-
$return = include 'download_pdf.php';这不会将信息加载到$return除非您在该 php 文件中有return,您可能会在此处回显某些内容,这将导致您所说的确切错误. -
是的,我没有重新调整任何变量。我只是为一个 php 文件创建 html 并包含该 php 文件。所以请向我提出解决此问题的任何建议
-
另一件事是,当我回显返回变量时,我可以在浏览器中看到整个 html,但遇到错误“标头已发送”