Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the PHP script in TCPDF?

Tags:

html

php

tcpdf

I have a table in Database like this

 expedition_name | Phone | CP    |
__________________________________________
    Starsindo    | 09890 | John  |
    Iron Bird    | 09891 | Gina  |
    MSA Cargo    | 09890 | John  |

Now I will create the PDF from that table with TCPDF using HTML function.

But I Still confuses how to combine that my code like this

  <?php

require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

// create new PDF document
 include "koneksi.php";
   $sql = "SELECT * FROM tb_exp_local";
   $hasil = mysql_query($sql);
   $data = mysql_fetch_array($hasil);

   $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

   // set font
   $pdf->SetFont('times', '', 11);

   // add a page
   $pdf->AddPage();



   $html = '<h2>List Of Expediton</h2>    //Title
<table border="1" cellspacing="3" cellpadding="4">
    <tr>
        <th>Expedition</th>                //head of column name
        <th align="center">Phoine</th>  //head of column name
        <th align="center">CP</th>       //head of column name
    </tr>
     while($data=mysql_fetch_array($hasil))
     { 
    <tr>
       <td>$data[nama_exp]</td>
    </tr>
     }   
</table>';


  $pdf->writeHTML($html, true, false, true, false, '');


   $pdf->Output('Local Expedition, 'I');

?>

Can Anyone help me, How to fix it? and the data can be write in PDF?

like image 288
MudMan23 Avatar asked Jul 19 '12 08:07

MudMan23


People also ask

Can we use PHP in script tag?

It's just a regular HTML <script> tag that calls a PHP file instead of a JavaScript file. But there's one catch: In that PHP file, you still have to use JavaScript.


1 Answers

you need to prepare your html with something like:

$html = '<h2>List Of Expediton</h2>    //Title
    <table border="1" cellspacing="3" cellpadding="4">
    <tr>
        <th>Expedition</th>                //head of column name
        <th align="center">Phoine</th>  //head of column name
        <th align="center">CP</th>       //head of column name
    </tr>';

while($data=mysql_fetch_array($hasil)) { 
    $html .= '<tr><td>'.$data['nama_exp'].'</td></tr>';
}   
$html .= '</table>';
like image 200
Sanjay Avatar answered Sep 21 '22 21:09

Sanjay