Exsport PDF

Untuk Pdf Materi yang sama Ada Disemester 6

1.Download Fpdf17 dan File Barang
Click here

Barang.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("dblapbarang")or die(mysql_error());
require('fpdf17/fpdf.php');
//Menampilkan data dari tabel di database
$tampung=mysql_query("SELECT * FROM Tbltoko") or die(mysql_error());
//Inisiasi untuk membuat header kolom
$k_kode = "";$k_nabar = "";$k_jenis = "";$k_harga = "";$k_jumlah = "";
//MEMBUAT FILE KOLOM
while($row = mysql_fetch_array($tampung))
{
 $kode = $row["kodee"];$nabar = $row["nabarr"];$jenis = $row["jeniss"];
    $harga = $row["hargaa"];$jumlah = $row["jumlahh"];
  $k_kode = $k_kode.$kode."\n";$k_nabar = $k_nabar.$nabar."\n";
    $k_jenis = $k_jenis.$jenis."\n";$k_harga = $k_harga.$harga."\n";
    $k_jumlah = $k_jumlah.$jumlah."\n";
//Create a new PDF file
$pdf = new FPDF('P','mm',array(210,297));
$pdf->AddPage();
//MEMBUAT JUDUL
$pdf->SetFont('Arial','B',13);
$pdf->Cell(80);
$pdf->Cell(30,10,'LAPORAN DATA BARANG',0,0,'C');
$pdf->Ln();
$pdf->Cell(80);
$pdf->Cell(30,10,'USAHA KREATIF MAHASISWA MEDICOM',0,0,'C');
$pdf->Ln();
}
//MENENTUKAN POSISI FIELD
$posisinamafield = 30;
//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(110,180,230);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',10);
$pdf->SetY($posisinamafield);
$pdf->SetX(50);
$pdf->Cell(25,8,'kodeedfsa',1,0,'C',1);
$pdf->SetX(75);
$pdf->Cell(25,8,'nabarr',1,0,'C',1);
$pdf->SetX(100);
$pdf->Cell(25,8,'jeniss ',1,0,'C',1);
$pdf->SetX(125);
$pdf->Cell(25,8,'hargaa',1,0,'C',1);
$pdf->SetX(150);
$pdf->Cell(25,8,'jumlahh',1,0,'C',1);
$pdf->Ln();
//Table position, under Fields Name
$Y_Table_Position = 38;
//Now show the columns
$pdf->SetFont('Arial','',10);
$pdf->SetY($Y_Table_Position);$pdf->SetX(50);
$pdf->MultiCell(25,6,$k_kode,1,'C');
$pdf->SetY($Y_Table_Position);$pdf->SetX(75);
$pdf->MultiCell(25,6,$k_nabar,1,'L');

$pdf->SetY($Y_Table_Position);$pdf->SetX(100);
$pdf->MultiCell(25,6,$k_jenis,1,'C');

$pdf->SetY($Y_Table_Position);$pdf->SetX(125);
$pdf->MultiCell(25,6,$k_harga,1,'C');

$pdf->SetY($Y_Table_Position);$pdf->SetX(150);
$pdf->MultiCell(25,6,$k_jumlah,1,'C');
$pdf->Output();?>


Contoh barang2.php => Lebih Rapih
<?php
mysql_connect("localhost","root","");
mysql_select_db("dblapbarang")or die(mysql_error());
$ambil = mysql_query("select * from Tbltoko");
$k_kode="";$k_nabar="";$k_jenis="";$k_harga="";$k_jumlah="";
while($data= mysql_fetch_array($ambil)){
$kode = $data[0];
$nabar = $data[1];
$jenis = $data[2];
$harga = $data[3];
$jumlah = $data[4];
$k_kode = $k_kode.$kode."\n";
$k_nabar = $k_nabar.$nabar."\n";
$k_jenis = $k_jenis.$jenis."\n";
$k_harga = $k_harga.$harga."\n";
$k_jumlah = $k_jumlah.$jumlah."\n";
}
require("fpdf17/fpdf.php");
$pdf = new FPDF("P","mm",array(200,200));
$pdf->AddPage();
$pdf->Cell(60);
$pdf->SetFont("arial","B",13);
$pdf->Cell(1,10,"Laporan Barang Perdagangan");
$pdf->Ln();
$pdf->Cell(70);
$pdf->Cell(1,10,"Jl.Gajah Mada No 23 A");
$pdf->Ln();

$pdf->SetFont("Arial","B","10");
$pdf->SetFillColor(200,200,200);
$pdf->SetY(40);
$pdf->SetX(40);
$pdf->Cell(25,8,"Kode Barang",1,0,"C",1);
$pdf->Cell(25,8,"Nama Barang",1,0,"C",1);
$pdf->Cell(25,8,"Jenis Barang",1,0,"C",1);
$pdf->Cell(25,8,"harga Barang",1,0,"C",1);
$pdf->Cell(30,8,"Jumlah Barang",1,0,"C",1);
$pdf->Ln();

$pdf->SetFont("Arial","",10);
$pdf->SetY(48);
$pdf->SetX(40);
$pdf->MultiCell(25,8,$k_kode,1,0,"C",1);
$pdf->SetY(48);
$pdf->SetX(65);
$pdf->MultiCell(25,8,$k_nabar,1,0,"C",1);
$pdf->SetY(48);
$pdf->SetX(90);
$pdf->MultiCell(25,8,$k_jenis,1,0,"C",1);
$pdf->SetY(48);
$pdf->SetX(115);
$pdf->MultiCell(25,8,$k_harga,1,0,"C",1);
$pdf->SetY(48);
$pdf->SetX(140);
$pdf->MultiCell(30,8,$k_jumlah,1,0,"C",1);

$pdf->output();
?>
==================================

Exsport PDF Exsport PDF Reviewed by Leo on 22:01 Rating: 5

No comments