Question

After creating a page in php, I am using mpdf to create a pdf that appears like the page. The page is a receipt, so some of its entries are variables. The code for the page that turns the receipt page ('Receipt_Template_2.php') into a pdf is:

<?php
include("MPDF57/mpdf.php");

ob_start();
include "Receipt_Template_2.php"; 
$template = ob_get_contents();
ob_end_clean();

$mpdf=new mPDF('','A4','','',32,25,27,25,16,13,'L'); 

$mpdf->WriteHTML($template);

$mpdf->Output('MyPDF.pdf', 'D');
?>

However, the actual receipt template page has php variables printed onto it correctly. However, these variables are not printed onto the receipt (the fields are left blank). Thank you.

I am mostly using session variables in my receipt template, such as below:

<div id="apDiv1"><img src="Receipt_Template_2.jpg" width="765" height="519"></div>
<div id="apDiv2">
<p><strong><?php echo $_SESSION['firstName'] . ' ' . $_SESSION['lastName'];?></strong>       </p>
  <p><?php echo $_SESSION['address'];?></p>
  <p><?php echo $_SESSION['city'] . ' ' . $_SESSION['province'];?></p>
  <p><?php echo $_SESSION['postal'];?></p>
  <p><?php echo $_SESSION['country'];?></p>
</div>
<div id="apDiv3"><?php echo $_SESSION['dateReceived'];?></div>
<div id="apDiv4"><?php echo date("Y-m-d");?></div>
<div id="apDiv5"><?php echo $_SESSION['locationIssued'];?></div>
<div id="apDiv18">$<?php echo $_SESSION['donationAmount'];?></div>
<div id="apDiv6"><?php echo $preReceiptNumber . $receiptNumber;?></div>
Was it helpful?

Solution

Try...

ob_start();
include "Receipt_Template_2.php"; 
$template = ob_get_contents();
ob_end_clean();

$mpdf->WriteHTML($template);

OTHER TIPS

try this (after import library):

$url = "Receipt_Template_2.php";
$CurlConnect = curl_init();
curl_setopt($CurlConnect, CURLOPT_URL, $url);
curl_setopt($CurlConnect, CURLOPT_RETURNTRANSFER, 1 );
$file_contents = curl_exec($CurlConnect);
curl_close($CurlConnect);
$CurlConnect = null;

echo $file_contents;
$html = ob_get_contents();

ob_end_clean();

$mpdf->WriteHTML($html);

$mpdf->Output();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top