Advertisement
nebukad

laporan pdf

Feb 8th, 2017
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. include 'config.php';
  3. include 'laporan.php';
  4.  
  5. // query list
  6. $sql    = "SELECT * FROM table WHERE field = '' ";
  7. $query  = $this->db->query($sql);
  8. $data   = $query->result();
  9.  
  10. // query sisa
  11. $sqlsisa    = "SELECT * FROM table WHERE field = '' ";
  12. $querysisa  = $this->db->query($sqlsisa);
  13. $sisa       = $querysisa->result();
  14.  
  15. $pdf = new Laporan();
  16. $pdf->AddPage('P', 'a4');
  17. $pdf->SetFont('Arial','',12);
  18. $pdf->SetMargins(5,10,0);
  19. $pdf->SetAutoPageBreak(0);
  20. $pdf->body($data, $sisa);
  21.  
  22. $pdf->Output();
  23. ?>
  24.  
  25.  
  26. // file laporan.php
  27. <?php
  28.  
  29. require('../assets/pdf/fpdf.php');
  30. class Laporan extends FPDF
  31. {
  32.     function Header()
  33.     {
  34.         // code header
  35.         //Pilih font Arial bold 15
  36.         $this->SetFont('Arial','B',12);
  37.         //Judul dalam bingkai
  38.         $this->SetLeftMargin(5);
  39.         $this->SetX(0);
  40.         $this->SetY(0);
  41.         $this->Cell(69,8,'LAPORAN ....','B',1,'L');
  42.         // Insert a logo in the top-left corner at 300 dpi
  43.         // $this->Image('http://path.com/assets/img/logo-cuci-medium.png',175,1,30);
  44.     }
  45.  
  46.     public function body($data, $sisa)
  47.     {
  48.         // code display body pdf
  49.         $this->SetX(200);
  50.         $this->SetY(12);
  51.  
  52.         $this->SetX(0);
  53.         $this->SetY(10);
  54.         $this->SetFont('Arial','',10);
  55.         $this->Ln(5);
  56.         $this->Cell(30,5,"SISA",0,0);
  57.         $this->Cell(40,5,": ". $sisa,0,1);
  58.  
  59.         foreach ($data as $row) {
  60.             $this->Cell(50,5,$row->field,'BR',0,'L');
  61.         }
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement