使用 html2pdf 库创建 HTML 到 PDF 文件
Create HTML to PDF file using html2pdf library
我正在使用 html2pdf 库在 wordpress 中生成 pdf 文件。使用这个我可以创建 pdf 文件,但是当我尝试打开这个文件时它显示错误:"format error : not a pdf or currupted"。
我的代码是:
$content = "<page><h1>Exemple d'utilisation</h1><br>Ceci est un <b>exemple d'utilisation</b>de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br></page>";
include('html2pdf/html2pdf.class.php');
try
{
ob_end_flush();
ob_get_clean();
ob_end_clean();
$html2pdf = new HTML2PDF('L', 'Legal', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content);
$html2pdf->Output("report.pdf",'D');
}
catch(HTML2PDF_exception $e) {
echo 'exceptional error='.$e;
exit;
}
请指出我哪里错了。
提前致谢。
也许,pdf 没有正确关闭,尝试在 try-block 的末尾添加 exit;
:
try
{
...
exit;
}
你确定Output
必须以大写字母开头?
我正在使用 html2pdf 库在 wordpress 中生成 pdf 文件。使用这个我可以创建 pdf 文件,但是当我尝试打开这个文件时它显示错误:"format error : not a pdf or currupted"。 我的代码是:
$content = "<page><h1>Exemple d'utilisation</h1><br>Ceci est un <b>exemple d'utilisation</b>de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br></page>";
include('html2pdf/html2pdf.class.php');
try
{
ob_end_flush();
ob_get_clean();
ob_end_clean();
$html2pdf = new HTML2PDF('L', 'Legal', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content);
$html2pdf->Output("report.pdf",'D');
}
catch(HTML2PDF_exception $e) {
echo 'exceptional error='.$e;
exit;
}
请指出我哪里错了。
提前致谢。
也许,pdf 没有正确关闭,尝试在 try-block 的末尾添加 exit;
:
try
{
...
exit;
}
你确定Output
必须以大写字母开头?