[英]How to convert an HTML page to PDF in PHP
<?php
include ('mpdf/mpdf.php');
$mpdf = new mpdf;
ob_start();
?>
<html>
<head></head>
<body>
My various content with table, dropdown menu and 2 include files.
</body>
</html>
<?php
$html = ob_get_contents();
ob_end_clean();
$mpdf->Output();
exit;
?>
Wondering why this function doesn't work and will only output empty pdf file. 想知道为什么这个功能不起作用,只会输出空的pdf文件。 I have tried many ways but it just doesn't work.
我已经尝试了很多方法,但是那是行不通的。 I have placed this function at the beginning of my code but it always outputs an empty file.
我已将此函数放在代码的开头,但是它始终输出一个空文件。
Try this code:- 试试这个代码:
<?php
$html = ob_get_contents();
ob_end_clean();
// You need to write html
$mpdf->WriteHTML($html);
// define path of your output file and set mode 'F' for saving
$mpdf->Output('filename.pdf','F');
exit;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.