greyhat49

fpdf

Jan 20th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.77 KB | None | 0 0
  1. <?php
  2. require "fpdf.php";
  3. //require "fpdfMultiCell.php";
  4. require "../../config.php";
  5.  
  6. class PDF extends FPDF
  7. {
  8.     /*
  9.     function LoadDataFromSQL($sql)
  10.     {
  11.       $hasil = mysqli_query($konek,$sql)or die(mysqli_error($konek));
  12.      
  13.       $data = array();
  14.       while($rows=mysqli_fetch_array($hasil)){
  15.         $data[] = $rows;
  16.     }
  17.       return $data;
  18.     }
  19.     */
  20.     // Colored table
  21.     function FancyTable($header, $data)
  22.     {
  23.       // Colors, line width and bold font
  24.       $this->SetFillColor(77,65,240);
  25.       $this->SetTextColor(255);
  26.       $this->SetDrawColor(128,0,0);
  27.       $this->SetLineWidth(.3);
  28.       $this->SetFont('','B');
  29.        /*  $w adalah variabel lebar dari kolom data
  30.                 dalam kasus ini, kolom no lebarnya 20, propinsi 100
  31.              dan upah 60 */
  32.       $w = array( 70, 50, 30, 50);
  33.       for($i=0;$i<count($header);$i++)
  34.         $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
  35.       $this->Ln();
  36.       // tentukan warna background and fontnya
  37.       $this->SetFillColor(224,235,255);
  38.       $this->SetTextColor(0);
  39.       $this->SetFont('');
  40.       // Data
  41.       $fill = false;
  42.       foreach($data as $row)
  43.       {
  44.        
  45.         $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
  46.         $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
  47.         $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);
  48.         $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);
  49.         $this->Ln();
  50.         $fill = !$fill;
  51.        
  52.       }
  53.       // Closing line
  54.       $this->Cell(array_sum($w),0,'','T');
  55.     }
  56.    
  57.     const DPI = 96;
  58.     const MM_IN_INCH = 25.4;
  59.     const A4_HEIGHT = 297;
  60.     const A4_WIDTH = 210;
  61.     // tweak these values (in pixels)
  62.     const MAX_WIDTH = 400;
  63.     const MAX_HEIGHT = 250;
  64.    
  65.     function pixelsToMM($val) {
  66.         return $val * self::MM_IN_INCH / self::DPI;
  67.     }
  68.     function resizeToFit($imgFilename) {
  69.         list($width, $height) = getimagesize($imgFilename);
  70.         $widthScale = self::MAX_WIDTH / $width;
  71.         $heightScale = self::MAX_HEIGHT / $height;
  72.         $scale = min($widthScale, $heightScale);
  73.         return array(
  74.             round($this->pixelsToMM($scale * $width)),
  75.             round($this->pixelsToMM($scale * $height))
  76.         );
  77.     }
  78.     function centreImage($img) {
  79.         list($width, $height) = $this->resizeToFit($img);
  80.         // you will probably want to swap the width/height
  81.         // around depending on the page's orientation
  82.         $this->Image(
  83.             /*$img, (self::A4_HEIGHT - $width) / 2,
  84.             (self::A4_WIDTH - $height) / 2,*/
  85.             $img,
  86.             10,
  87.             20,
  88.             $width,
  89.             $height
  90.         );
  91.     }
  92.    
  93.     // Page footer
  94.     function Footer()
  95.     {
  96.         // Position at 1.5 cm from bottom
  97.         $this->SetY(-15);
  98.         $this->SetTextColor(0,0,0);
  99.         // Arial italic 8
  100.         $this->SetFont('Arial','I',8);
  101.         // Page number
  102.         $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  103.     }
  104. }
  105.  
  106. $href = $_REQUEST['profile_id'];
  107. $pdf = new PDF();
  108.  
  109. // header tabel
  110. $header = array('No Reg', 'Nama', 'Jenis Kriminal', 'foto');
  111. // buat query SQLmu disini
  112. //$query="select no_reg, nama, jenis_kriminal from bio_tr";
  113. $query = 'select *
  114.             from
  115.                 bio_tr btr
  116.                     inner join
  117.                 bio_pl bpl
  118.                     inner join
  119.                 pasal psl
  120.                     inner join
  121.                 foto ft
  122.             on
  123.                 btr.id_tr = ft.id_pemilik
  124.                     and
  125.                 btr.id_tr = psl.id_tersangka
  126.                     and
  127.                 btr.id_tr = bpl.pelapor_tr
  128.                     and                            
  129.                 btr.id_tr = '.$href.'
  130.             order by
  131.                 ft.created
  132.             desc
  133.                 limit 1';
  134. //$data = $pdf->LoadDataFromSQL($query);
  135. $hasil = mysqli_query($konek,$query)or die(mysqli_error($konek));
  136.  
  137. $row = mysqli_fetch_array($hasil);
  138. /*
  139. $data = array();
  140. while($rows = mysqli_fetch_array($hasil)){
  141.     $data[] = $rows;
  142. }
  143. */
  144. $pdf->AliasNbPages();
  145. $pdf->AddPage();
  146.  
  147. //HEADER
  148. $pdf->SetFont('Arial','B', 15);
  149. $pdf->SetFillColor(48,126,204);
  150. $pdf->SetTextColor(255,255,255);
  151. $pdf->SetDrawColor(164,165,166);
  152. $pdf->SetLineWidth(.3);
  153.  
  154. $pdf->Cell(190,10,'DATA IDENTITAS',0,1,'C',true);
  155. $pdf->Ln();
  156. //END HEADER
  157.  
  158. $pdf->centreImage('../dataInsert/'.$row['dir_foto'].'');
  159.  
  160.  
  161. //tentukan ukuran dan jenis form
  162. $pdf->SetFont('Arial','',11);
  163. $pdf->SetTextColor(0);
  164.  
  165. $pdf->setX(100);
  166. $pdf->Cell(40,5,'Nama',1,0,'L');
  167. $pdf->Cell(6,5,' : ',1,0,'L');
  168. $pdf->Cell(50,5,''.$row['nama'].'',1,0,'L');
  169. $pdf->Ln();
  170.  
  171. $pdf->setX(100);
  172. $pdf->Cell(40,5,'No Induk Registrasi',1,0,'L');
  173. $pdf->Cell(6,5,' : ',1,0,'L');
  174. $pdf->Cell(50,5,''.substr($row['no_reg'],0,-10).'',1,0,'L');
  175. $pdf->Ln();
  176.  
  177. $pdf->setX(100);
  178. $pdf->Cell(40,5,'Tanggal Lahir',1,0,'L');
  179. $pdf->Cell(6,5,' : ',1,0,'L');
  180. $pdf->Cell(50,5,''.$row['tgl_lahir'].'',1,0,'L');
  181. $pdf->Ln();
  182.  
  183. $pdf->setX(100);
  184. $pdf->Cell(40,5,'Alamat',1,0,'L');
  185. $pdf->Cell(6,5,' : ',1,0,'L');
  186. $pdf->Cell(50,5,''.$row['alamat'].'',1,0,'L');
  187. $pdf->Ln();
  188.  
  189. $pdf->setX(100);
  190. $pdf->Cell(40,5,'Jenis Kelamin',1,0,'L');
  191. $pdf->Cell(6,5,' : ',1,0,'L');
  192. $pdf->Cell(50,5,''.$row['kelamin'].'',1,0,'L');
  193. $pdf->Ln();
  194.  
  195. $pdf->setX(100);
  196. $pdf->Cell(40,5,'Warga Negara',1,0,'L');
  197. $pdf->Cell(6,5,' : ',1,0,'L');
  198. $pdf->Cell(50,5,''.$row['wn'].'',1,0,'L');
  199. //$pdf->FancyTable($header,$data);
  200. $pdf->Output();
  201. ?>
Advertisement
Add Comment
Please, Sign In to add comment