When I try to print the table in the file_html.php it prints the static table with some error(that's a different question). However, when the php tags for the posted data are included in the file with the post variables, the pdf generated displays nothing at all except for the anchor tag which is at the bottom of the page.
Here is the index.php :-
require_once("dompdf/dompdf_config.inc.php");
require_once("dompdf/dompdf_config.custom.inc.php");
spl_autoload_register('DOMPDF_autoload');
function pdf_create($html, $filename, $paper, $orientation, $stream=TRUE)
{
$dompdf = new DOMPDF();
$dompdf->set_paper($paper,$orientation);
$dompdf->load_html_file('http://localhost/pdf/file_html.php');
$dompdf->render();
$dompdf->stream($filename.".pdf");
}
$filename = 'billofsale';
$dompdf = new DOMPDF();
$html = file_get_contents('http://localhost/pdf/file_html.php');
pdf_create($html,$filename,'A4','portrait');
And here is the file_html.php which consists the form with the post variable. Note : when the php with the post is removed the table prints out in the pdf.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
}
table {
border-collapse: collapse;
border-spacing: 0;
width:100%;
}
body{
font: normal medium/1.4 sans-serif;
}
th{
text-align: center;
border: 3px solid #ccd;
}
td{
padding: 0.25rem;
text-align: left;
border: 2px solid #ccc;
}
tbody tr:nth-child(odd){
background: #eee;
}
tbody:before, thead:after { display: none; }
</style>
</head>
<body>
<?php
if(isset($_POST['submit'])){
?>
<p>
<table>
<thead><th colspan="2">Purchaser's Information</th></thead>
<tbody>
<tr>
<td colspan="2">Purchaser's Name : <?php echo $_POST['pname']; ?></td>
</tr>
<tr>
<td colspan="2">Purchaser's Address : <?php echo $_POST['padd']; ?></td>
</tr>
<tr>
<td>City/Town : <?php echo $_POST['pcity']; ?> </td>
<td>Province : <?php echo $_POST['ppro']; ?></td>
</tr>
<tr>
<td>Postal Code :<?php echo $_POST['ppcode']; ?></td>
<td>Home Tel No :<?php echo $_POST['ptelno']; ?></td>
</tr>
<tr>
<td>Business Tel :<?php echo $_POST['pbtel']; ?></td>
<td>Email :<?php echo $_POST['pemail']; ?></td>
</tr>
<tr>
<td>Driver License : <?php echo $_POST['pdriverlic']; ?></td>
<td>Expiry Date :<?php echo $_POST['pdriverexp']; ?></td>
</tr>
</tbody>
</table>
</p>
<?php
}
?>
<a href="index.php">Print </a>
</body>
</html>