donglei7152
2014-09-29 12:31
浏览 114
已采纳

使用mpdf生成pdf

I am trying to generate data from database to pdf using mpdf. and i am trying like this

<?php

include("../mpdf/mpdf.php");
$id= $_GET['order_id'];
include('../connect.php');
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10); 
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("My Title");
$mpdf->SetAuthor("Company");
$mpdf->SetWatermarkText("Paid");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');

$ss1 = "select orders.order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Billing' AND orders.order_id=".$_GET['order_id']."";
                $mq1 = mysql_query($ss1) or die(mysql_error());
                $rr1 = mysql_fetch_array($mq1);

                $billing = $rr1['address'];

                $country = $rr1['country'];
                $state = $rr1['state'];
                $city = $rr1['city'];
                $pin = $rr1['pin'];

                $ss2 = "select orders.order_id, orders.company_id, lead_address.address, lead_address.address_category, lead_address.country, lead_address.state, lead_address.company_id, lead_address.city,lead_address.pin from orders INNER JOIN lead_address ON orders.company_id=lead_address.company_id where lead_address.address_category='Shipping' AND orders.order_id=".$_GET['order_id']."";

                $mq2 = mysql_query($ss2) or die(mysql_error());
                $rr2 = mysql_fetch_array($mq2);

                $shipping = $rr2['address'];

                $country1 = $rr2['country'];
                $state1 = $rr2['state'];
                $city1 = $rr2['city'];
                $pin1 = $rr2['pin'];


$sql =  "select * from before_order_line_items where order_id = ".$_GET['order_id']." ";
$query = mysql_query($sql);             

$html = '
<html>
<head>
<style>
body {font-family: sans-serif;
    font-size: 10pt;
}
p {    margin: 0pt;
}
td { vertical-align: top; }
.items td {
    border-left: 0.1mm solid #000000;
    border-right: 0.1mm solid #000000;
}
table thead td { background-color: #EEEEEE;
    text-align: center;
    border: 0.1mm solid #000000;
}
.items td.blanktotal {
    background-color: #FFFFFF;
    border: 0mm none #000000;
    border-top: 0.1mm solid #000000;
    border-right: 0.1mm solid #000000;
}
.items td.totals {
    text-align: right;
    border: 0.1mm solid #000000;
}
</style>
</head>
<body>

<!--mpdf
<htmlpageheader name="myheader">
<table width="100%"><tr>
<td width="50%" style="color:#0000BB;"><span style="font-weight: bold; font-size: 14pt;"><img src="netelity.png" /></span><br /></td>
<td width="50%" style="text-align: right;">Invoice No.<br /><span style="font-weight: bold; font-size: 12pt;">0012345</span></td>
</tr></table>
</htmlpageheader>

<htmlpagefooter name="myfooter">
<div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
Page {PAGENO} of {nb}
</div>
</htmlpagefooter>

<sethtmlpageheader name="myheader" value="on" show-this-page="1" />
<sethtmlpagefooter name="myfooter" value="on" />
mpdf-->

<div style="text-align: right">Date: '.date('jS F Y').'</div>

<table width="100%" style="font-family: serif;" cellpadding="10">
<tr>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt; color: #555555; font-family: sans;">Billing Address</span><br /><br />'.$billing.'<br />'.$country.' , '.$state.'<br />'.$city.' - '.$pin.'</td>
<td width="10%">&nbsp;</td>
<td width="45%" style="border: 0.1mm solid #888888;"><span style="font-size: 7pt; color: #555555; font-family: sans;">Shipping Address</span><br /><br />'.$shipping.'<br />'.$country1.', '.$state1.'<br />'.$city1.' - '.$pin1.'</td>
</tr>
</table>


<table class="items" width="100%" style="font-size: 9pt;">
<thead>
<tr>

<td width="10%">No</td>
<td width="20%">Item</td>
<td width="10%">UOM</td>
<td width="10%">Price</td>
<td width="10%">Qty</td>
<td width="10%">Disc%</td>
<td width="10%">Tax%</td>
<td width="10%">Frt</td>
<td width="10%">Total</td>
</tr>
</thead>
<tbody>
<!-- ITEMS HERE -->
';
while($row = mysql_fetch_array($query))
{
'
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['item'].' <br> '.$row['description'].'</td>
<td>'.$row['uom'].'</td>
<td>'.$row['selling_price'].'</td>
<td>'.$row['quantity'].'</td>
<td>'.$row['discount'].'</td>
<td>'.$row['tax'].'</td>
<td>'.$row['freight'].'</td>
<td>'.$row['total'].'</td>
</tr>
';
}
'

</tbody>
</table>
<div style="text-align: center; font-style: italic;">Payment terms: payment due in 30 days</div>
</body>
</html>
';

$mpdf->WriteHTML($html);

$mpdf->Output(); exit;

exit;

?>

Only Shipping and billing address are getting displayed. From the second table its not showing anything. It shows blank.

How to do this?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhezi2285 2014-09-29 12:43
    已采纳

    You're forgetting to add the $html in your while loop.

    '
    <tr>
    <td>'.$row['id'].'</td>
    <td>'.$row['item'].' <br> '.$row['description'].'</td>
    <td>'.$row['uom'].'</td>
    <td>'.$row['selling_price'].'</td>
    <td>'.$row['quantity'].'</td>
    <td>'.$row['discount'].'</td>
    <td>'.$row['tax'].'</td>
    <td>'.$row['freight'].'</td>
    <td>'.$row['total'].'</td>
    </tr>
    ';
    

    should be

    $html .= '
    <tr>
    <td>'.$row['id'].'</td>
    <td>'.$row['item'].' <br> '.$row['description'].'</td>
    <td>'.$row['uom'].'</td>
    <td>'.$row['selling_price'].'</td>
    <td>'.$row['quantity'].'</td>
    <td>'.$row['discount'].'</td>
    <td>'.$row['tax'].'</td>
    <td>'.$row['freight'].'</td>
    <td>'.$row['total'].'</td>
    </tr>
    ';
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题