rianto isaac's Weblog

rianto utomo isaac sahala utomo

php-pdf, create pdf pake fpdf

leave a comment »

file2 yg dibuthkan:
1. fpdf.php
2. fpdf.css
3. folder font (isinya nama2 font dgn extension php)

perintah standard untuk menampilkan:

<?php
require(‘fpdf.php’);
pdf=new FPDF();
pdf->AddPage();
pdf->SetFont(‘Arial’,’B’,20);
pdf->Cell(40,10,’Hello Dunia Tips dan Trik Pemrograman PHP!’);
pdf->Output();
?>
dengan perintah diatas akan menghasilkan 1 halaman pdf bertuliskan
“Hello Dunia Tips dan Trik Pemrograman PHP!”
berikut coding php untuk mengambil data dari mysql dan menampilkannya di pdf:
<?php
require(“fpdf.php”);
include(“msr_con.php”);
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont(‘Arial’,’B’,12);
//$pdf->MultiCell();
$result = mysql_query(“SELECT * FROM msr_user order by name”);
$pdf->Cell(40,10,”Name”);
$pdf->Cell(40,10,”Username”);
$pdf->Cell(40,10,”Title”);
$pdf->Ln(10);
while($row = mysql_fetch_array($result))
{
$pdf->Cell(40,10,$row[‘name’]);
$pdf->Cell(40,10,$row[‘username’]);
$pdf->Cell(40,10,$row[‘title’]);
$pdf->Ln(10);
}
mysql_close($con);
$pdf->Output();
?>
rianto utomo dari berbagai sumber dan telah dikembangkan sendiri

 

Written by isaaconi

Oktober 27, 2009 pada 1:23 pm

Tinggalkan komentar