Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // library codeigniter file Pdf.php
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- require_once APPPATH.'third_party/tcpdf/tcpdf.php';
- class Pdf extends TCPDF {
- var $text_footer;
- var $logo_company;
- public function __construct($addData = array()) {
- parent::__construct();
- }
- }
- ----------------------------------------------------------------------------
- // function controller codeigniter
- function toPdf()
- {
- $this->load->library('Pdf');
- $pdf = new PDF();
- // set default header data
- $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
- // set default monospaced font
- $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
- // set margins
- //$pdf->SetMargins(10, 10, 10, false);
- $pdf->SetHeaderMargin(10);
- //$pdf->setFooterMargin(10);
- //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
- // set auto page breaks
- $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
- $pdf->setPrintHeader(false);
- $pdf->setPrintFooter(false);
- // set image scale factor
- $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
- $pdf->AddPage();
- $pdf->SetFont('helvetica', 'B', 20);
- // Title
- $pdf->Cell(0, 15, 'INVOICE', 0, 1, 'C', 0, '', 0, false, 'M', 'M');
- $pdf->SetFont('helvetica', '', 12);
- $pdf->Cell(0, 15, date('d F Y'), 0, 1, 'C', 0, '', 0, false, 'M', 'M');
- $pdf->SetFont('helvetica', '', 8);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'PT Angin Ribut', 0, 0, 'T', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'No RM : 131555123', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Jl Kenanga Indah No. 12', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Tom Cruise', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Jelembar Baru - Grogol Petamburan', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Jl. Besar Utama No 78', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Jakarta Barat - DKI Jakarta', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Tebet Timur - Tebet Kota', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Telp: 021-1234-555-2344', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Jakarta Selatan - DKI Jakarta', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Email: helo@anginribut.com', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Telp: 0811-2334-2334', 0, 1, 'L', 0, '', 0);
- $pdf->setX(25);
- $pdf->Cell(70, 0, 'Web: www.anginribut.com', 0, 0, 'L', 0, '', 0);
- $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
- $pdf->Cell(70, 0, 'Email: tomcruis@indo.com', 0, 1, 'L', 0, '', 0);
- // contoh data
- $data = array();
- for($i=1;$i<151;$i++) {
- $data[$i] = array(
- "col_a" => 'col a '.$i,
- "col_b" => 'col b '.$i,
- "col_c" => 'col c '.$i,
- "col_d" => 'col d '.$i,
- "col_e" => 'col e '.$i,
- "col_f" => 'col f '.$i,
- "col_g" => 'col g '.$i,
- "col_h" => 'col h '.$i,
- "col_i" => 'col i '.$i,
- "col_j" => 'col j '.$i,
- );
- }
- $pdf->ln();
- // header
- $pdf->SetFont('helvetica', 'B', 5);
- $pdf->Cell(19, 4, 'Tanggal Kunjungan', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Departemen', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Nama', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'KK', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Tgl Lahir', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Jenis K', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Desa', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'RT', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'RW', 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, 'Jumlah Kunjungan', 1, 1, 'L', 0, '', 0);
- shuffle($data);
- foreach($data as $r)
- {
- $pdf->SetFont('helvetica', '', 5);
- $pdf->Cell(19, 4, $r['col_a'].' '.$i, 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_b'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_c'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_d'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_e'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_f'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_g'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_h'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_i'], 1, 0, 'L', 0, '', 0);
- $pdf->Cell(19, 4, $r['col_j'], 1, 1, 'L', 0, '', 0);
- }
- $pdf->Output('example_me.pdf', 'I');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement