Jump to content

Recommended Posts

Hi, i have to generate an invoice from my database. every thing works well. i have read posts here about using buffer and i am till now sucessfully able to generate the invoice.

 

The Problem come when i try to use headers and footers in the page. i get an error in the pdf file "damaged or corrupted".

 

here is my code.

 

<?php 
include('config.php');
session_start();
$invoice = $_SESSION['lid'];
include("/mpdf/mpdf.php");

$mpdf=new mPDF('en-x','A4','','',32,25,47,47,10,10); 
$header = '
<table width="100%" style="border-bottom: 1px solid #000000; vertical-align: bottom; font-family: serif; font-size: 9pt; color: #000088;"><tr>
<td width="19%"><img src="logo.jpg" width="126px" /></td>
<td width="68%" align="center"><p align="center" style="font-size:14px; color:#000000;"><strong>Sapience Business Events Private Limited </strong></p>
  <p align="center" style="font-size:12px; color:#000000;"><strong>Invoice</strong></p></td>
<td width="13%" style="text-align: right;"> </td>
</tr></table>
';
$footer = '<table width="100%" style="border-bottom: 1px solid #000000; vertical-align: bottom; font-family: serif; font-size: 9pt; color: #000088;"><tr>
<td><div align="" style="float:left; padding:0,20,30,10">
    <div align="center"></div>
  </div>
  <div align="center">
    <div align="center">
      <p allign="center"><span style="font-size:12px; color:#000000;">#92/3-3, The Pearl, Mosque Road, Frazer Town, Bangalore - 560 005, India</span>      </p>
      <p allign="center"><span style="font-size:12px; color:#000000;">E-mail: trainings@sapienceevents.com</span></p>
      <p allign="center"><span style="font-size:12px; color:#000000;">Tel: +91 80 41241378    Fax: +91 80 41263672</span></p>
    </div>
  </div>
</td>
</tr></table>';


$mpdf->SetHTMLHeader($header);
//$mpdf->SetHTMLHeader($headerE,'E');
$mpdf->SetHTMLFooter($footer);
//$mpdf->SetHTMLFooter($footerE,'E');
ob_start();


?>
<head>
<style>
table.sample {
border-width: 1px;
border-spacing: 0px;
border-style: solid;
border-color: #000000;
border-collapse: collapse;
background-color: #ffffff;
}
table.sample th {
border-width: 1px;
border-style: solid;
border-color: #000000;
background-color: #ffffff;
}
table.sample td {
border-width: 1px;
border-style: solid;
border-color: #000000;
background-color: #ffffff;
}
</style>
</head>
<body><table width="629">
  <tr>
    <td width="768"><table width="577">
      <tr>
        <td width="177">Invoice Number:</td>
        <td width="325"><?php echo $_SESSION["invoice_number"]; ?></td>
        <td width="59"> </td>
      </tr>
      <tr>
        <td>Invoice Date:</td>
        <td><?php echo $_SESSION["invoice_date"]; ?></td>
        <td> </td>
      </tr>
      <tr>
        <td>Training Code:</td>
        <td><?php echo $_SESSION["training_code"]; ?></td>
        <td> </td>
      </tr>
      <tr>
        <td>Reference Date:</td>
        <td><?php echo $_SESSION["reference_date"]; ?></td>
        <td> </td>
      </tr>
      <tr>
        <td>Due Date for payment:</td>
        <td><?php echo $_SESSION["due_date"]; ?></td>
        <td> </td>
      </tr>
      <tr>
        <td>Invoice Currency:</td>
        <td>USD</td>
        <td> </td>
      </tr>
      <tr>
        <td>Event Details:</td>
        <td><p><?php echo $_SESSION["ed_training_name"]; ?></p>
            <p><?php echo $_SESSION["ed_training_date"]; ?> <?php echo $_SESSION["ed_training_place"]; ?></p></td>
        <td> </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td> </td>
  </tr>
  <tr>
    <td><table width="434">
      <tr>
        <td width="35">To:</td>
        <td width="226"><?php echo $_SESSION["iaddr"]; ?></td>
        <td width="157"> </td>
      </tr>
      <tr>
        <td> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td>Attn:</td>
        <td><?php echo $_SESSION["officials_name"]; ?></td>
        <td> </td>
      </tr>
    </table>
      <table width="772" border="0" bordercolor="#000000" class="sample" style="border-collapse: collapse">
        <tr>
          <td width="64" bgcolor="#CCCCCC" style="border-collapse: collapse"><div align="center">Sl. No.</div></td>
          <td width="101" bgcolor="#CCCCCC" style="border-collapse: collapse"><div align="center">Particulars</div></td>
          <td width="155" bgcolor="#CCCCCC" style="border-collapse: collapse"><div align="center">Price per Participant</div></td>
          <td width="173" bgcolor="#CCCCCC" style="border-collapse: collapse"><div align="center">No. of Participants</div></td>
          <td width="255" bgcolor="#CCCCCC" style="border-collapse: collapse"><div align="center">Amount</div></td>
        </tr>
    <tr>
      <td><div align="center"></div></td>
      <td><div align="center"></div></td>
      <td><div align="center"></div></td>
      <td><div align="center"></div></td>
      <td><div align="center"></div></td>
      </tr>
    <tr>
      <td style="border-collapse: collapse"><div align="center">1</div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $_SESSION["tn"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $_SESSION["ppc"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $_SESSION["noc"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center">
        <?php $amount = $_SESSION["ppc"] * $_SESSION["noc"]; echo $amount; $tamount = $_SESSION["ppc"] * $_SESSION["noc"]; ?>
      </div></td>
      </tr> 
<?php 
$pert_query = mysql_query ("SELECT * FROM `perticulars` WHERE `invoice` =$invoice") or die(mysql_error());
$i = 2;
 $total = 0; 
 while($perticulars = mysql_fetch_array($pert_query, MYSQL_ASSOC)) {
?>
<tr>
      <td style="border-collapse: collapse"><div align="center"><?php echo $i;
  $i++; 
   ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars["perticulars"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars["ppc"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars["nop"]; ?></div></td>
      <td style="border-collapse: collapse"><div align="center">
        <?php $amount = $perticulars["ppc"] * $perticulars["nop"]; echo $amount;?>
      </div></td>
      </tr><?php $total = $total + $amount;
} ?>
    <tr>
      <td colspan="4" style="border-collapse: collapse"><div align="center">Total</div></td>
      <td style="border-collapse: collapse"><div align="center"><?php $sum = $total + $tamount; echo $sum; ?></div></td>
      </tr>
  </table>
<p> </p>

      <table width="260" border="0">
        <tr>
          <td width="161">Invoice Amount</td>
          <td width="22"> </td>
          <td width="63">3015</td>
        </tr>
        <tr>
          <td>Amount paid</td>
          <td> </td>
          <td>0</td>
        </tr>
        <tr>
          <td>Balance amount to be paid</td>
          <td> </td>
          <td>3015</td>
        </tr>
      </table>      
      <p>Our Bank Reference:</p>
      <table width="402" border="0" bordercolor="#000000" class="sample">
        <tr>
          <td style="border-collapse: collapse">Bank Name:</td>
          <td width="215" style="border-collapse: collapse">HDFC BANK LTD</td>
        </tr>
        <tr>
          <td style="border-collapse: collapse">Bank Address:</td>
          <td style="border-collapse: collapse">CMH Road, Indira Nagar Bangalore - 560038</td>
        </tr>
        <tr>
          <td style="border-collapse: collapse">Beneficiary:</td>
          <td style="border-collapse: collapse">Sapience Business Events Private limited</td>
        </tr>
        <tr>
          <td style="border-collapse: collapse">Account Number:</td>
          <td style="border-collapse: collapse">0184-256000-4182</td>
        </tr>
        <tr>
          <td style="border-collapse: collapse">Swift Code:</td>
          <td style="border-collapse: collapse">HDFCINBB</td>
        </tr>
        <tr>
          <td style="border-collapse: collapse">ABA Number:</td>
          <td style="border-collapse: collapse">021-000-021</td>
        </tr>
      </table>
      <p style="font-size:14px; color:#000000;">International delegates please note, when paying by bank transfer the <strong>bank charges should be added to the total amount due.</strong> Payment
        is required within the due date from the date of booking. When making payment please quote the invoice/order number. Send your remittance advice/transaction slip to the email address suman.s@sapienceevents.com or fax to +91 80 41263672</p>    </td>
  </tr>
</table>
</body>';
<?php

$html = ob_get_contents();
ob_end_clean();

$mpdf->WriteHTML($html);

$mpdf->Output();
exit;
?>

Link to comment
https://forums.phpfreaks.com/topic/228948-anyone-fimilar-with-mpdf/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.