0

在 php 中创建页面后,我正在使用 mpdf 创建一个看起来像页面的 pdf。该页面是一张收据,因此它的一些条目是变量。将收据页面 ('Receipt_Template_2.php') 转换为 pdf 的页面的代码是:

<?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');
?>

但是,实际的收据模板页面上正确打印了 php 变量。但是,这些变量不会打印到收据上(这些字段留空)。谢谢你。

我主要在收据模板中使用会话变量,如下所示:

<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>
4

2 回答 2

6

尝试...

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

$mpdf->WriteHTML($template);
于 2013-10-30T21:05:45.713 回答
0

试试这个(在导入库之后):

$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();
于 2016-02-06T21:26:10.637 回答