【发布时间】:2021-10-31 22:18:08
【问题描述】:
我使用 composer 安装了dompdf
composer require dompdf/dompdf
在我的控制器中我有这个
use Dompdf\Dompdf;
....
function actionPdf() {
$dompdf = new DOMPDF();
$dompdf->loadHtml('<h1>hello world</h1>');
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
}
但我得到的只是一个空白 PDF。当我查看app.log 时,我看到了这个
2021-09-02 20:20:41 [127.0.0.1][262][-][error][yii\web\HeadersAlreadySentException] yii\web\HeadersAlreadySentException: Headers already sent in on line 0. in C:\xampp\htdocs\yii2\vendor\yiisoft\yii2\web\Response.php:373
Stack trace:
#0 C:\xampp\htdocs\yii2\vendor\yiisoft\yii2\web\Response.php(346): yii\web\Response->sendHeaders()
#1 C:\xampp\htdocs\yii2\vendor\yiisoft\yii2\base\Application.php(398): yii\web\Response->send()
#2 C:\xampp\htdocs\yii2\frontend\web\index.php(64): yii\base\Application->run()
#3 {main}
任何想法如何解决这个问题?谢谢
【问题讨论】:
-
您是否尝试添加
// Output the generated PDF to Browser $dompdf->stream();,这是文档:github.com/dompdf/dompdf#quick-start