Deskripsi
Membuat Report PDF menggunakan TCPDF , diharapkan user dapat memahami konsep dasar membuat Report PDF menggunakan class dari TCPDF.
How To
1. Download Class TCPDF
http://www.tcpdf.org/
2. Buat folder TEST di webserver anda.
3. Extract TCPDF beserta isi classnya ke dalam folder TEST.
4. Struktur folder anda sekarang :
TEST ---> TCPDF ---> File and library TCPDF Here
5. Sekarang buat file index.php di dalam folder TEST, sehingga strukturnya menjadi seperti ini :
TEST ---> TCPDF ---> File and library TCPDF Here
---> index.php
6. Copy paste Code dibawah ini
<?php
require_once('tcpdf/tcpdf.php');
// for setting variable you can goto
tcpdf/config/tcpdf_config, you can change them
// create new PDF document; (i set PDF_UNIT from
Milimeter to Centimeter)
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//set margin page (all direction)
//setMargins(LEFT,TOP,RIGHT) in CM (centimeter), it's looks like MS Word :D
$pdf->SetMargins(1, 3, 1,true);
//setup Header
$pdf->SetHeaderMargin(1); // margin header 1 CM
$pdf->setPrintHeader(true); // enabled ? true
$pdf->SetHeaderData(false, 0, "Hellow World Header", "mynotework.blogspot.com"); //your text here
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', 15)); // data font header
//Set Footer
$pdf->SetFooterMargin(1); // margin footer 1 CM
$pdf->setPrintFooter(true); // enabled ? true
//$pdf->setFooterData($tc=array(0,64,0), $lc=array(0,64,128));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
//$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set auto page breaks
$pdf->SetAutoPageBreak(true, 1.3); // it's use when u use table, to increase break page
// Set font
$pdf->SetFont('dejavusans', '', 14, '', true); // set global font
// Add a page, MUST BE DECLARATION at lease 1 statement
$pdf->AddPage();
// Set some content to print
$html = ' Hello World TCPDF';
// Print text using writeHTML()
$pdf->writeHTML($html, true, 0, true, 0);
// Buat output buffer page(I) / create file (F)
$pdf->Output('example_001.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
?>
if you will use table ? simple ! , just write you HTML , for example
//some example
$html = ' <table>
<tr nobr="true" border="1">
<td nowrap="true">this if my first cell</td>
</tr>
</table>';
// Print text using writeHTML()
$pdf->writeHTML($html, true, 0, true, 0);
*nobr="true" => no breakline
*border="1" => show border cell
*nowrap="true" => cell can increase width automatically when character veryyyy loooong :D
one more , you can customize TCPDF setting on
tcpdf/config/tcpdf_config.php ALL OF SETTINGS VARIABLE IN THERE and it's familiar with MS WORD.
still not understand ?
you can download my sample and running in your webserver wamp/xampp (apache) :
Download Sample Tutorial
Instruction :
1. before download take a survey first to help our advertiser.
2. after download, just drop extract the file (.rar) to your webserver (WWW / Htdocs)
3. Access via localhost using browser and you will get the result.
4. every download = you give a cup of cofee to me, thank you very much it make me wants to create a better tutorial.
5. this file, include tcpdf library.