无法使用 DOMPDF 下载 pdf

Unable to downlaod pdf using DOMPDF

我查了很多资源,但我的问题无法解决。我试图通过包含 PHP 文件来生成 PDF。但是现在我陷入了 "Unable to stream pdf: headers already sent" 错误。我还压缩了我的代码并删除了空格。 这是我的代码。

<?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));
?>

尝试使用 output buffering

替换

$return = include 'download_pdf.php';

ob_start();
include 'download_pdf.php';
$return  = ob_get_contents();
ob_end_clean();