0
我一直在嘗試使用mPDF生成發票。我有一個名爲「invoice-layout.php」的佈局頁面,它與數據庫進行通信以獲取客戶的詳細信息。我希望將此頁面轉換爲pdf。我正在使用以下代碼進行轉換,但只有一兩分鐘後纔會顯示空白的PDF頁面。PHP文件不能轉換爲PDF使用mPDF
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>
'echo $ content;'看看它是否是你想要的值。 – Matt
刪除一切,但只有一行的HTML看看是否有用,從基礎開始 – 2016-02-13 23:44:42
@Dagon我試過,當我直接把某些東西當作文本,它會被打印出來,但是當我添加一個簡單的html頁面時。只是空白的PDF頁面。 –