使用MPDF在PHP中生成PDF
我通过composer成功安装了mpdf。
这是我的 PHP 代码:
require_once __DIR__ . '/vendor/autoload.php';
$mpdf=new \Mpdf\Mpdf();
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';
$mpdf->output($file,'I');
PDF 不会生成。我在 Chrome 和 Firefox 中尝试过。 autoload.php 的位置是正确的。 我也尝试了 D、F 和 S,作为 $mpdf->output
的第二个参数,但没有任何效果。
I installed mpdf successfully via composer.
Here is my PHP code:
require_once __DIR__ . '/vendor/autoload.php';
$mpdf=new \Mpdf\Mpdf();
$mpdf->WriteHTML("<h1>test</h1>");
$file='abcd.pdf';
$mpdf->output($file,'I');
PDF won't generate. I tried in Chrome and Firefox.
The location of autoload.php is correct.
I tried D, F and S as well, as the second argument for $mpdf->output
, none worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码实际上有效,请仔细检查您的
PHP版本
并请注意,MPDF仅与
php≥5.6.0和&lt兼容; 7.4.0。
https://mpdf.github.io//大约是mpdf/unignts-v7.html
your code actually works, please double check your
php version
and note that mpdf is compatible only with
PHP ≥ 5.6.0 and < 7.4.0.
https://mpdf.github.io/about-mpdf/requirements-v7.html
您可以使用传递文件名称的outputhttpdownload方法,它将起作用!
You can use the OutputHttpDownload method passing the name of your file and it will work!
使用此功能创建一个临时目录,然后执行此操作
Use this create a temporary directory and then do this