Ruang Web Hosting Indonesia - Solusi Handal, Cepat dan Murah

Posts Tagged ‘pdf’

php code : generate pdf using mysql and php

April 4, 2007 - 10:09 am No Comments

From http://www.ros.co.nz/pdf/

<?php
// test the table functions
error_reporting(E_ALL);
include(’class.ezpdf.php’);
$pdf =& new Cezpdf(’a4′,’portrait’);
$pdf->selectFont(’./fonts/Helvetica’);
$pdf->ezSetCmMargins(1.5,2,1.5,1.5);

$pdf->addText(370,790,8,”LAMPIRAN I : Keputusan Menteri Tenaga Kerja dan”,0);
$pdf->addText(422,780,8,”Transmigrasi Republik Indonesia”,0);
$pdf->addText(422,770,8,”Nomor : PER.09/MEN/V/2005″,0);
$pdf->addText(422,760,8,”Tanggal : 25-5-2005″,0);
$pdf->line(422,758,555,758);
$pdf->ezSetDy(-50, ‘makeSpace’);

$pdf->ezText(’DATA PEGAWAI PENGAWAS KETENAGAKERJAAN’,10, array(’justification’ => ‘center’));

//————————————————–
// you will have to change these to your settings
$host = ‘172.27.1.28′;
$user = ‘root’;
$password = ’server’;
$database = ‘lp2tk’;
$query = ’select * from dat_k01_detail’;
//————————————————–
// open the connection to the db server
$link = mysql_connect($host,$user,$password);
// change to the right database
mysql_select_db($database);
// initialize the array
$data = array();
// do the SQL query
$result = mysql_query($query);
// step through the result set, populating the array, note that this could also have been written:
// while($data[] = mysql_fetch_assoc($result)) {}
while($data[] = mysql_fetch_array($result, MYSQL_ASSOC)) {}
// make the table

$pdf->ezText(’Triwulan’, 8);
$pdf->ezText(’Tahun’, 8);
$pdf->ezText(’Kab/Kota’, 8);
$pdf->ezText(’Kode’, 8);
$pdf->addText(80,729,8,”:”,0);
$pdf->addText(80,719,8,”:”,0);
$pdf->addText(80,710,8,”:”,0);
$pdf->addText(80,701,8,”: K1″,0);

$pdf->ezSetDy(-10, ‘makeSpace’);
$pdf->ezTable($data,array(’nomor’=>’NO.’, ‘jabatan’=>’JABATAN PENGAWAS KETENAGAKERJAAN’, ‘umum’=>’UMUM’, ’sp1′=>’1′, ’sp2′=>’2′, ’sp3′=>’3′, ’sp4′=>’4′, ’sp5′=>’5′, ’sp6′=>’6′, ’sp7′=>’7′, ’sp8′=>’8′, ’sp9′=>’9′, ’sp10′=>’10′, ’sp11′=>’11′, ‘ppns’=>’PPNS’, ‘jumlah’=>’JUMLAH’, ‘keterangan’=>’KETERANGAN’)
,”, array(’innerLineThickness’ => 1,’outerLineThickness’ => 1.2,’showHeadings’=>1,’shaded’=>1,’showLines’=>1, ‘xPos’=>’center’ ,’xOrientation’=>’center’, ‘width’=>535));
$pdf->ezSetDy(-10, ‘makeSpace’);

$pdf->ezText(’<b>Keterangan Kolom Spesialis</b>
1 = Pesawat Uang Bejana Tekan
2 = Pesawat Angkat Angkut
3 = Pesawat Tenaga dan Produksi
4 = Instalasi Listrik, Lift
5 = Penanggulangan Kebakaran
6 = Konstruksi Bangunan
‘,8, array(’justification’ => ‘left’));

$pdf->addText(200,570,8,”7 = Kesehatan Kerja”,0);
$pdf->addText(200,561,8,”8 = Lingkungan Kerja”,0);
$pdf->addText(200,552,8,”9 = Jamsostek”,0);
$pdf->addText(200,543,8,”10 = Pengupahan dan Waktu Kerja”,0);
$pdf->addText(200,534,8,”11 = Keselamatan Kerja Kimia”,0);

$pdf->addText(395,570,8,”(Wilayah/Daerah, Tanggal, Bulan, Tahun)”,0);
$pdf->addText(375,561,8,”Kepala Instansi atau Kepala Unit Kerja Pengawasan”,0);
$pdf->addText(410,552,8,”Ketenagakerjaan Kabupaten/Kota”,0);
$pdf->addText(435,530,8,”(……………………….)”,0);

//$pdf->ezTable($data,$cols,”, array(’xPos’=>90,’xOrientation’=>’right’,'width’=>300 ,’cols’=>array(’nomor’=>array(’justification’=>’right’),’jabatan’=>array(’width’=>400))));
// do the output, this is my standard testing output code, adding ?d=1
// to the url puts the pdf code to the screen in raw form, good for checking
// for parse errors before you actually try to generate the pdf file.
if (isset($d) && $d){
$pdfcode = $pdf->output(1);
$pdfcode = str_replace(”\n”,”\n<br>”,htmlspecialchars($pdfcode));
echo ‘<html><body>’;
echo trim($pdfcode);
echo ‘</body></html>’;
} else {
$pdf->stream();
$pdf->ezStartPageNumbers(30,50,20,”,”,1);
$pdf->ezStopPageNumbers();
}
ezNewPage()
?>

ros.pdf

clip.png