0

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>

2 Answers 2

7

Try...

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

$mpdf->WriteHTML($template);
Sign up to request clarification or add additional context in comments.

5 Comments

Edit my answer. It should go above the line where you WriteHTML. Your WriteHTML will need modifying.
The php code does not print now. However, the variables are not printed on the receipt pdf even though they appear fine on the receipt template.
How are the variables passed to the template?
The variables are session variables.
Can you post a snippet of your template with variables
0

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.