I have been trying to generate an invoice using mPDF. I have a layout page called "invoice-layout.php" which communicates with the database to get the details of the customer. I want this page to be converted to pdf. I am using the following code for conversion, but only a blank pdf page shows up after a minute or two.
mpdf code:
<?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;
?>
and here is the code of my php layout page:
<?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>
Try edit your HTML code to more simple. mPDF have sometimes problems with too nested or too complicated html/css/style code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.