Skip to main content

FPDF dengan CodeIgniter

Cetak Surat Keputusan

Controller:

<?php


//File in controller named surat_keputusan.php

defined('BASEPATH') OR exit('No direct script access allowed');

class Cetak_surat_keputusan extends CI_Controller {

public function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();       
        $this->db->select();
        $this->db->from('surat.config_sk');       
        $query = $this->db->get();
       
        return $query->result();
       
    }

public function index()
{
        if(isset($_GET['id_sk'])){
           
        date_default_timezone_set('Asia/Jakarta');
           
            $query=$this->load->database('surat',TRUE)->get_where('config_sk',array('id_sk'=>$_GET['id_sk']));
            $data_sk=array(
                'id_sk'=>'',
                'sk_nomor'=>'',
                'sk_kelompok'=>'',
                'sk_judul_1'=>'',
                'sk_judul_2'=>'',
                'sk_judul_3'=>'',
                'sk_judul_4'=>'',
                'sk_judul_5'=>'',               
                'sk_tanggal'=>'',
                'sk_rektor'=>'',
                'sk_rektor_nik'=>'',               
            );
            if($query->num_rows()>0){
                $row=$query->row();
                $data_sk['id_sk']=$row->id_sk;
                $data_sk['sk_nomor']=$row->sk_nomor;
                $data_sk['sk_kelompok']=$row->sk_kelompok;               
                $data_sk['sk_judul_1']=$row->sk_judul_1;
                $data_sk['sk_judul_2']=$row->sk_judul_2;
                $data_sk['sk_judul_3']=$row->sk_judul_3;
                $data_sk['sk_judul_4']=$row->sk_judul_4;
                $data_sk['sk_judul_5']=$row->sk_judul_5;               
               
                $data_sk['sk_tanggal']=$row->sk_tanggal;
                $data_sk['sk_rektor']=$row->sk_rektor;
                $data_sk['sk_rektor_nik']=$row->sk_rektor_nik;               
            }

            //jarak_dan_ukuran
            $jarak_atas = '0.5'; $jarak_kiri = '4'; $panjang_gambar = '0.7'; $tinggi_gambar = '1'; $jarak_titik_dua_dari_pinggir = '1.2'; $jarak_isi_dari_titik_dua = '0.1'; $lebar_isi = '7'; $lebar_isi_dalam = '5.4'; $lebar_isi_dalam_nomor = '5.2'; $jarak_tembusan = '2';
            //   
            //jarak_dan_ukuran
            $jarak_atas = '0.5'; $jarak_kiri = '4'; $panjang_gambar = '0.7'; $tinggi_gambar = '1'; $jarak_titik_dua_dari_pinggir = '1.2'; $jarak_isi_dari_titik_dua = '0.1'; $lebar_isi = '7'; $lebar_isi_dalam = '5.4'; $lebar_isi_dalam_nomor = '5.2'; $jarak_tembusan = '2';
            //
           
        //STANDART
                $this->load->library('fpdf_gen');       
                $this -> fpdf=new FPDF('P','in',array(8.5,10.7)); 
                $this -> fpdf->AddPage();
       
        // FONT
            $jenis_font_reguler= 'BOOKOS';
            $jenis_font_italic= 'BOOKOSI';
            $jenis_font_bold= 'BOOKOSB';

            $this -> fpdf->AddFont($jenis_font_reguler,'','BOOKOS.php');
            $this -> fpdf->AddFont($jenis_font_italic,'','BOOKOSI.php');
            $this -> fpdf->AddFont($jenis_font_bold,'','BOOKOSB.php');
            $this -> fpdf->SetFillColor(255,0,0); $ukuran_font='11';

        $this->fpdf->SetFont($jenis_font_bold,'',$ukuran_font);
       
        $this->fpdf->SetFillColor(255,0,0);
//ISI

//LogoUII

  $this->fpdf->Image('http://localhost/administrasi/assets/images/uii.png',$jarak_kiri,$jarak_atas,$panjang_gambar,$tinggi_gambar);

//JUDUL
        $this->fpdf->ln(1.3);
        $this->fpdf->Cell(0.5); //jarak dari pinggir
        $this->fpdf->Cell($lebar_isi,0.2,'SURAT KEPUTUSAN REKTOR UNIVERSITAS ISLAM INDONESIA',0,0,'C',0,'');
        $this->fpdf->SetFont($jenis_font_reguler,'',$ukuran_font);

        $this->fpdf->ln(0.2);
        $this->fpdf->Cell(0.5);
        //NOMOR_SURAT
            $bulan = $data_sk['sk_tanggal'];
            //bulan_romawi
            $bulan_romawi = date('m', strtotime($data_sk['sk_tanggal']));
            $dayList = array(
                    '01' => 'I',
                    '02' => 'II',
                    '03' => 'III',
                    '04' => 'IV',
                    '05' => 'V',
                    '06' => 'VI',
                    '07' => 'VII',
                    '08' => 'VIII',
                    '09' => 'IX',
                    '10' => 'X',
                    '11' => 'XI',
                    '12' => 'XII'
                );
           
        if ($data_sk['sk_nomor'] <> ""){$nomor_surat_cetak=$data_sk['sk_nomor'];}else{$nomor_surat_cetak= "      ";}

        $this->fpdf->Cell($lebar_isi,0.2, 'NOMOR '. $nomor_surat_cetak . '/SK-Rek/'. $data_sk['sk_kelompok'] .'/'. $dayList[$bulan_romawi]. '/' . date('Y', strtotime($data_sk['sk_tanggal'])) ,0,0,'C',0,'');
       
        $this->fpdf->SetFont($jenis_font_bold,'',$ukuran_font);

        $this->fpdf->ln(0.2);
        $this->fpdf->Cell(0.5);
        $this->fpdf->Cell($lebar_isi,0.2,'TENTANG',0,0,'C',0,'');
       
//JUDUL 10
$this->fpdf->ln(0.2);
       
if ($data_sk['sk_judul_1'] == null) {} else {
    $this->fpdf->Cell(0.5);
    $this->fpdf->MultiCell($lebar_isi,0.2,$data_sk['sk_judul_1'],0,'C',0);
}

if ($data_sk['sk_judul_2'] == null) {} else {
    $this->fpdf->Cell(0.5);
    $this->fpdf->MultiCell($lebar_isi,0.2,$data_sk['sk_judul_2'],0,'C',0);
}

if ($data_sk['sk_judul_3'] == null) {} else {
    $this->fpdf->Cell(0.5);
    $this->fpdf->MultiCell($lebar_isi,0.2,$data_sk['sk_judul_3'],0,'C',0);
}

if ($data_sk['sk_judul_4'] == null) {} else {
    $this->fpdf->Cell(0.5);
    $this->fpdf->MultiCell($lebar_isi,0.2,$data_sk['sk_judul_4'],0,'C',0);
}

if ($data_sk['sk_judul_5'] == null) {} else {
    $this->fpdf->Cell(0.5);
    $this->fpdf->MultiCell($lebar_isi,0.2,$data_sk['sk_judul_5'],0,'C',0);
    $this->fpdf->ln(0.1);
}

//bismillah
$this->fpdf->ln(0.1); $this->fpdf->Cell(0.5); $this->fpdf->SetFont($jenis_font_italic,'',$ukuran_font);
$this->fpdf->Cell($lebar_isi,0.2,'Bismillahirrahmanirrahiim',0,0,'C',0,'');

$this->fpdf->ln(0.3); $this->fpdf->Cell(0.5); $this->fpdf->SetFont($jenis_font_reguler,'',$ukuran_font);
$this->fpdf->Cell($lebar_isi,0.2,'REKTOR UNIVERSITAS ISLAM INDONESIA,',0,0,'C',0,'');
       
//TANDA TANGAN REKTOR
//bismillah
$this->fpdf->ln(0.2);
$this->fpdf->SetFont($jenis_font_italic,'',$ukuran_font);
$this->fpdf->Cell(8,0.2,'Billahitaufiq wal hidayah',0,0,'C',0,'');       

//--------------- TANDA TANGAN REKTOR
$this->fpdf->SetFont($jenis_font_reguler,'',$ukuran_font);
$this->fpdf->ln(0.3);
$this->fpdf->Cell(4);
$this->fpdf->MultiCell(4,0.3,'Ditetapkan di Yogyakarta',0,'',0);
$this->fpdf->Cell(4); //jarak dari pinggir
$this->fpdf->Cell(1,0.2,"Pada tanggal: ",0,0,'11');//lebar kolom b.
$this->fpdf->SetFont($jenis_font_reguler,'U',$ukuran_font);
$this->fpdf->Cell(0.1); //jarak antara c. dan Bahwa

//
$tahun_sk = date('Y', strtotime($data_sk['sk_tanggal']));
$list_bulan = array(
        '01' => 'Januari',
        '02' => 'Februari',
        '03' => 'Maret',
        '04' => 'April',
        '05' => 'Mei',
        '06' => 'Juni',
        '07' => 'Juli',
        '08' => 'Agustus',
        '09' => 'September',
        '10' => 'Oktober',
        '11' => 'November',
        '12' => 'Desember'
    );
   
$bulan_sk = $list_bulan[date('m', strtotime($data_sk['sk_tanggal']))];

if($data_sk['sk_nomor'] == null){$tanggal_sk = '    ';
}else
{$tanggal_sk = date('d', strtotime($data_sk['sk_tanggal']));}

//HIJRIYAH
//hijriah
            function makeInt($angka)
            {
            if ($angka < -0.0000001)
            {
            return ceil($angka-0.0000001);
            }
            else
            {
            return floor($angka+0.0000001);
            }
            }

            function konvhijriah($tanggal)
            {
            $array_bulan = array("Muharram", "Safar", "Rabiul Awwal", "Rabiul Akhir",
            "Jumadil Awwal","Jumadil Akhir", "Rajab", "Sya’ban",
            "Ramadhan","Syawwal", "Dzulqaidah", "Dzulhijjah");

            $date = makeInt(substr($tanggal,8,2));
            $month = makeInt(substr($tanggal,5,2));
            $year = makeInt(substr($tanggal,0,4));
            if (($year>1582)||(($year == "1582") && ($month > 10))||(($year == "1582") && ($month=="10")&&($date >14)))
            {
            $jd = makeInt((1461*($year+4800+makeInt(($month-14)/12)))/4)+
            makeInt((367*($month-2-12*(makeInt(($month-14)/12))))/12)-
            makeInt( (3*(makeInt(($year+4900+makeInt(($month-14)/12))/100))) /4)+
            $date-32075;
            }
            else
            {
            $jd = 367*$year-makeInt((7*($year+5001+makeInt(($month-9)/7)))/4)+
            makeInt((275*$month)/9)+$date+1729777;
            }

            $wd = $jd%7;
            $l = $jd-1948440+10632;
            $n=makeInt(($l-1)/10631);
            $l=$l-10631*$n+354;
            $z=(makeInt((10985-$l)/5316))*(makeInt((50*$l)/17719))+(makeInt($l/5670))*(makeInt((43*$l)/15238));
            $l=$l-(makeInt((30-$z)/15))*(makeInt((17719*$z)/50))-(makeInt($z/16))*(makeInt((15238*$z)/43))+29;
            $m=makeInt((24*$l)/709);
            $d=$l-makeInt((709*$m)/24);
            $y=30*$n+$z-30;
            $g = $m-1;

            /* $final = "     $array_bulan[$g] $y H"; */
            /* $final = "$d $array_bulan[$g] $y H";   */
            $final = " " . "$d $array_bulan[$g] $y H";
            return $final;
            }

//HIJRIYAH
            $datehijriah = konvhijriah($data_sk['sk_tanggal']);
            $this->fpdf->MultiCell(2.5,0.2, ' '. $datehijriah,0,'L',0);

//tanggal
$this->fpdf->SetFont($jenis_font_reguler,'',$ukuran_font);
$this->fpdf->Cell(5);
$this->fpdf->MultiCell(4,0.2,'   ' . $tanggal_sk .' '. $bulan_sk .' '. $tahun_sk .' M',0,'L',0);
/* $this->fpdf->MultiCell(4,0.2,$datehijriah ,0,'L',0); */

$this->fpdf->ln(0.05);
$this->fpdf->Cell(4);
$this->fpdf->MultiCell(4,0.2,'Rektor,',0,'L',0);

$this->fpdf->ln(0.8);
$this->fpdf->Cell(4);
$this->fpdf->MultiCell(4,0.2,$data_sk['sk_rektor'],0,'L',0);
$this->fpdf->Cell(4);
$this->fpdf->MultiCell(4,0.2,$data_sk['sk_rektor_nik'],0,'L',0);

//TEMBUSAN

//SELESAI
       
/*         echo $this->fpdf->Output('hello_world.pdf','D'); */
        echo $this->fpdf->Output('I');
       
    }

    }   
}



Libraries: fpdf_gen.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Name:  FPDF
*
* Author: Jd Fiscus
*            jdfiscus@gmail.com
*         @iamfiscus
*         
*
* Origin API Class: http://www.fpdf.org/
*
* Location: http://github.com/iamfiscus/Codeigniter-FPDF/
*         
* Created:  06.22.2010
*
* Description:  This is a Codeigniter library which allows you to generate a PDF with the FPDF library
*
*/

class Fpdf_gen {
       
    public function __construct() {
       
        require_once APPPATH.'third_party/fpdf/fpdf-1.8.php';
        define('FPDF_FONTPATH', APPPATH.'third_party/fpdf/font/');
               
        $pdf = new FPDF();
        $pdf->AddPage();

        $CI =& get_instance();
        $CI->fpdf = $pdf;
       
    }
   
}

Comments

  1. Sands Casino Resort: Resorts & Casinos | Tucson, Arizona
    At Sands Casino Resort we operate with 인카지노 the highest standard of security and the highest standard of security available 메리트카지노 to all. We're septcasino here to help make your gaming

    ReplyDelete

Post a Comment

Popular posts from this blog

Layar Biru versi PHP Bagian 1 (file prefil_dbf.php)

file config.php <?php $db_uname = 'root'; $db_passwd = ''; $db_name = 'layar_biru'; //database yang dipilih $db_host = 'localhost'; $xbase_dir = 'D:\ACADEMIC\htdocs\layar_biru\files'; $die_on_mysql_error = false; // when investigating errors, set this to true $from_encoding=""; //Encoding of database, e.g. CP866 or empty, if convert is not required     file prefil.dbf   <?php include "config.php";            // please copy the config.sample.php and edit the correct fields include "classes/XBase/Table.php"; include "classes/XBase/Column.php"; include "classes/XBase/Record.php"; include "classes/DBFhandler.php"; use XBase\Table;  // Initializing vars ini_set( 'memory_limit', '2048M' ); set_time_limit( 0 ); $time_start = time(); $files = scandir($xbase_dir) or die ("Error! Could not open directory '$xbase_dir'."); $conn = new mysqli($db_host,...

Converter dbf ke MYSQL

Banyak tool yang dipakai dan direkomendasikan orang untuk mengkonversi database , khususnya DBF ke MySQL. Ada yang menggunakan / menyarankan Navicat, CDBF for Linux , dbf2mysql, MySQL Migration Toolkit , dll. Bahkan ada pula yang mau bersusah-payah melakukannya dengan cara tradisionil dan ribet, yaitu dengan menggunakan MS Access: ekspor file ini, ganti syntax-nya menjadi sql, bla..bla..bla… dsb. Setelah menyimak semuanya, endingnya ternyata gak bikin happy. Meski begitu saya hargai effort mereka. Karena dari upaya mereka itulah kita menjadi tahu bahwa tool yang ini dan itu tidak cocok  dipakai. Tool yang saya pakai adalah Full Convert Enterprise (FCE). Komen saya terhadap tool ini cuma satu, keren! Kenapa? Karena bukan hanya source DBF saja yang bisa di-convert, tapi juga source lainnya (Interbase/Firebird, Oracle , Paradox, SQL Server, dll). Download: Full Convert Enterprise Full Version di sini (size 4.7 MB) Password: bayusibond Berikut adalah langkah-langkah m...