我正在使用 dompdf 从 php 文件生成 PDF。这是文件的完整代码:
<?php
// INCLUDEM CONFIGUL SI INITIALIZAM CLASELE DE SISTEM
require_once 'config.php';
require_once 'initialize.php';
require_once("/dompdf/dompdf_config.inc.php");
// Database
// Conectarea LA BAZA DE DATE !!!
$db = new MySQLDatabase();
// Session
// SESIUNEA CARE TINE UTILIZATORUL LOGAT !
$session=new Session();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="main.css" media="all" rel="stylesheet" type="text/css">
<link href='http://fonts.googleapis.com/css?family=Allura' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="<?php echo HTTP_FRONT; ?>js/jquery-1.8.3.js"></script>
<title>Sanovita</title>
</head>
<body>
<script>
$(document).ready(function(){
$('.AdaugaCategoriile p#1').hide();
$('.AdaugaCategoriile p#2').hide();
$('.AdaugaCategoriile p#3').hide();
$('.AdaugaCategoriile p#4').hide();
$('#categorie').change(function(){
var categorie = $(this).val();
$('.AdaugaCategoriile p#1').hide();
$('.AdaugaCategoriile p#2').hide();
$('.AdaugaCategoriile p#3').hide();
$('.AdaugaCategoriile p#4').hide();
$('.AdaugaCategoriile p#'+categorie).show();
});
});
</script>
<div id="Body">
<div id="Header">
<div id="HeaderLogo">
<a href="index.php"><img src="images/logo.png"></a>
</div>
<div id="Menu">
<div class="clear"></div>
</div>
</div>
<div id="Content">
<div class="Categorii">
<?php
// daca nu exista id-ul produsului
if(isset($_GET['id']))
{
$res = $db->query("SELECT * FROM `vanzari` WHERE `id_client`=".$_GET['id']." AND `finalizat`=0");
$categoriile = '<table>
<th width="2%">Nr.</th>
<th width="15%">Nume Client</th>
<th width="15%">Nume Angajat</th>
<th width="15%">Produs</th>
<th>Data</th>
<th>Cantitate</th>
<th width="10%">Total pret</th>
<th width="15%">Stare</th>
<th>Actiuni</th>';
$x = 1;
// AFISEZ PRODUSELE
for($i=0; $i<$res->num_rows; $i++)
{
$client = $db->query("SELECT * FROM `clienti` WHERE `id`=".$res->rows[$i]['id_client']."");
$produs_vanzare = $db->query("SELECT * FROM `produse` WHERE `id`=".$res->rows[$i]['id_produs']."");
$angajat = $db->query("SELECT * FROM `utilizatori` WHERE `id`=".$res->rows[$i]['id_angajat']."");
if($res->rows[$i]['finalizat'] == 0)
{
$status = 'In curs de finalizare';
}
else
{
$status = 'Finalizat';
}
// daca produsul e par
if(($i%2)==0)
{
$categoriile .= "
<tr class='odd'>
<td><p>".$x."</p></td>
<td><p>".$client->row['nume_client']."</p></td>
<td><p>".$angajat->row['firstname']. ' ' . $angajat->row['lastname']."</p></td>
<td><p>".$produs_vanzare->row['name']."</p></td>
<td><p>".$res->rows[$i]['data']."</p></td>
<td><p>".$res->rows[$i]['bucati']."</p></td>
<td><p>".$res->rows[$i]['total_pret']." RON</p></td>
<td><p>".$status."</p></td>
<td><a href='".HTTP_FRONT."vanzari.php?id_vanzare=".$res->rows[$i]['id']."&id=".$client->row['id']."'><p>Sterge</p></a></td>
</tr>";
}
else
{
$categoriile .= "
<tr class='even'>
<td><p>".$x."</p></td>
<td><p>".$client->row['nume']."</p></td>
<td><p>".$angajat->row['firstname']. ' ' . $angajat->row['lastname']."</p></td>
<td><p>".$produs_vanzare->row['name']."</p></td>
<td><p>".$res->rows[$i]['data']."</p></td>
<td><p>".$res->rows[$i]['bucati']."</p></td>
<td><p>".$res->rows[$i]['total_pret']." RON</p></td>
<td><p>".$status."</p></td>
<td><a href='".HTTP_FRONT."vanzari.php?id_vanzare=".$res->rows[$i]['id']."&id=".$client->row['id']."'><p>Sterge</p></a></td>
</tr>";
}
$x++;
}
$categoriile .= "</table><div class='clear'></div>";
if(!isset($session->data['finalizat']))
{
echo $categoriile;
}
}
?>
</div>
</div>
<div class="clear"></div>
<div id="Footer">
<p>Copyright © 2013</p>
</div>
</div>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("factura.pdf");
?>
dompdf 只生成了 HTML 部分,但没有显示 php 部分。在配置中,DOM_ENABLE_PHP 设置为 true。可能是什么问题?