我一直在尝试使用mPDF生成发票。我有一个名为“invoice-layout.php”的布局页面,它与数据库通信以获取客户的详细信息。我希望将此页面转换为pdf。我使用以下代码进行转换,但一两分钟后只显示一个空白的pdf页面。
mpdf代码:
<?php
include("mpdf/mpdf.php");
ob_start();
include 'invoice-layout.php';
$content = ob_get_clean();
$mpdf = new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true;
$mpdf->SetProtection(array('print'));
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($content);
$mpdf->Output();
exit;
?>
这是我的php布局页面的代码:
<?php
include("db_connect.php");
session_start();
$qry=$conn -> query("SELECT * FROM orders WHERE id=88");
$row=mysqli_fetch_assoc($qry);
$user_id = $_SESSION['client_id'];
$customer=$conn->query("SELECT * FROM customer WHERE id='$user_id'");
$client=$customer->fetch_array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
//some scripts and design styles
</head>
<body>
// tables here containing variables having values from the database.
</body>
</html>
答案 0 :(得分:-1)
尝试将HTML代码编辑为更简单。 mPDF有时会出现嵌套太多或太复杂的html / css / style代码的问题。