Advertisement
gotopa

Table TCPDF

Aug 26th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. // library codeigniter file Pdf.php
  2. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3. require_once APPPATH.'third_party/tcpdf/tcpdf.php';
  4. class Pdf extends TCPDF {
  5.  
  6. var $text_footer;
  7. var $logo_company;
  8. public function __construct($addData = array()) {
  9. parent::__construct();
  10. }
  11. }
  12.  
  13. ----------------------------------------------------------------------------
  14. // function controller codeigniter
  15. function toPdf()
  16. {
  17. $this->load->library('Pdf');
  18. $pdf = new PDF();
  19. // set default header data
  20. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  21.  
  22. // set default monospaced font
  23. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  24.  
  25. // set margins
  26. //$pdf->SetMargins(10, 10, 10, false);
  27. $pdf->SetHeaderMargin(10);
  28. //$pdf->setFooterMargin(10);
  29. //$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  30.  
  31. // set auto page breaks
  32. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  33. $pdf->setPrintHeader(false);
  34. $pdf->setPrintFooter(false);
  35.  
  36. // set image scale factor
  37. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  38.  
  39. $pdf->AddPage();
  40. $pdf->SetFont('helvetica', 'B', 20);
  41. // Title
  42. $pdf->Cell(0, 15, 'INVOICE', 0, 1, 'C', 0, '', 0, false, 'M', 'M');
  43. $pdf->SetFont('helvetica', '', 12);
  44. $pdf->Cell(0, 15, date('d F Y'), 0, 1, 'C', 0, '', 0, false, 'M', 'M');
  45.  
  46. $pdf->SetFont('helvetica', '', 8);
  47. $pdf->setX(25);
  48. $pdf->Cell(70, 0, 'PT Angin Ribut', 0, 0, 'T', 0, '', 0);
  49. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  50. $pdf->Cell(70, 0, 'No RM : 131555123', 0, 1, 'L', 0, '', 0);
  51.  
  52. $pdf->setX(25);
  53. $pdf->Cell(70, 0, 'Jl Kenanga Indah No. 12', 0, 0, 'L', 0, '', 0);
  54. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  55. $pdf->Cell(70, 0, 'Tom Cruise', 0, 1, 'L', 0, '', 0);
  56.  
  57. $pdf->setX(25);
  58. $pdf->Cell(70, 0, 'Jelembar Baru - Grogol Petamburan', 0, 0, 'L', 0, '', 0);
  59. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  60. $pdf->Cell(70, 0, 'Jl. Besar Utama No 78', 0, 1, 'L', 0, '', 0);
  61.  
  62. $pdf->setX(25);
  63. $pdf->Cell(70, 0, 'Jakarta Barat - DKI Jakarta', 0, 0, 'L', 0, '', 0);
  64. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  65. $pdf->Cell(70, 0, 'Tebet Timur - Tebet Kota', 0, 1, 'L', 0, '', 0);
  66.  
  67. $pdf->setX(25);
  68. $pdf->Cell(70, 0, 'Telp: 021-1234-555-2344', 0, 0, 'L', 0, '', 0);
  69. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  70. $pdf->Cell(70, 0, 'Jakarta Selatan - DKI Jakarta', 0, 1, 'L', 0, '', 0);
  71.  
  72. $pdf->setX(25);
  73. $pdf->Cell(70, 0, 'Email: helo@anginribut.com', 0, 0, 'L', 0, '', 0);
  74. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  75. $pdf->Cell(70, 0, 'Telp: 0811-2334-2334', 0, 1, 'L', 0, '', 0);
  76.  
  77. $pdf->setX(25);
  78. $pdf->Cell(70, 0, 'Web: www.anginribut.com', 0, 0, 'L', 0, '', 0);
  79. $pdf->Cell(25, 0, '', 0, 0, 'C', 0, '', 0);
  80. $pdf->Cell(70, 0, 'Email: tomcruis@indo.com', 0, 1, 'L', 0, '', 0);
  81.  
  82. // contoh data
  83. $data = array();
  84. for($i=1;$i<151;$i++) {
  85. $data[$i] = array(
  86. "col_a" => 'col a '.$i,
  87. "col_b" => 'col b '.$i,
  88. "col_c" => 'col c '.$i,
  89. "col_d" => 'col d '.$i,
  90. "col_e" => 'col e '.$i,
  91. "col_f" => 'col f '.$i,
  92. "col_g" => 'col g '.$i,
  93. "col_h" => 'col h '.$i,
  94. "col_i" => 'col i '.$i,
  95. "col_j" => 'col j '.$i,
  96. );
  97. }
  98.  
  99. $pdf->ln();
  100. // header
  101. $pdf->SetFont('helvetica', 'B', 5);
  102. $pdf->Cell(19, 4, 'Tanggal Kunjungan', 1, 0, 'L', 0, '', 0);
  103. $pdf->Cell(19, 4, 'Departemen', 1, 0, 'L', 0, '', 0);
  104. $pdf->Cell(19, 4, 'Nama', 1, 0, 'L', 0, '', 0);
  105. $pdf->Cell(19, 4, 'KK', 1, 0, 'L', 0, '', 0);
  106. $pdf->Cell(19, 4, 'Tgl Lahir', 1, 0, 'L', 0, '', 0);
  107. $pdf->Cell(19, 4, 'Jenis K', 1, 0, 'L', 0, '', 0);
  108. $pdf->Cell(19, 4, 'Desa', 1, 0, 'L', 0, '', 0);
  109. $pdf->Cell(19, 4, 'RT', 1, 0, 'L', 0, '', 0);
  110. $pdf->Cell(19, 4, 'RW', 1, 0, 'L', 0, '', 0);
  111. $pdf->Cell(19, 4, 'Jumlah Kunjungan', 1, 1, 'L', 0, '', 0);
  112.  
  113. shuffle($data);
  114. foreach($data as $r)
  115. {
  116. $pdf->SetFont('helvetica', '', 5);
  117. $pdf->Cell(19, 4, $r['col_a'].' '.$i, 1, 0, 'L', 0, '', 0);
  118. $pdf->Cell(19, 4, $r['col_b'], 1, 0, 'L', 0, '', 0);
  119. $pdf->Cell(19, 4, $r['col_c'], 1, 0, 'L', 0, '', 0);
  120. $pdf->Cell(19, 4, $r['col_d'], 1, 0, 'L', 0, '', 0);
  121. $pdf->Cell(19, 4, $r['col_e'], 1, 0, 'L', 0, '', 0);
  122. $pdf->Cell(19, 4, $r['col_f'], 1, 0, 'L', 0, '', 0);
  123. $pdf->Cell(19, 4, $r['col_g'], 1, 0, 'L', 0, '', 0);
  124. $pdf->Cell(19, 4, $r['col_h'], 1, 0, 'L', 0, '', 0);
  125. $pdf->Cell(19, 4, $r['col_i'], 1, 0, 'L', 0, '', 0);
  126. $pdf->Cell(19, 4, $r['col_j'], 1, 1, 'L', 0, '', 0);
  127. }
  128. $pdf->Output('example_me.pdf', 'I');
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement