我检查了大量资源,但我的问题无法解决。我尝试通过包含PHP文件生成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));
?>
答案 0 :(得分:0)
尝试使用output buffering
替换
$return = include 'download_pdf.php';
与
ob_start();
include 'download_pdf.php';
$return = ob_get_contents();
ob_end_clean();