KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
pdf.php
Ir a la documentación de este archivo.
1 <?php
27 include_once LIBRARY_PATH.'fpdf/fpdf.php';
28 
29 class PDF extends FPDF
30 {
31  //Cabecera de página
32  function Header()
33  {
34  $this->Ln(10);
35  }
36 
37  //Pie de página
38  function Footer()
39  {
40 
41  $config = Config::read('config');
42  $active_app = Router::get_application();
43  //Posición: a 1,5 cm del final
44  $this->SetY(-21);
45  //Arial italic 8
46  $this->SetFont('Arial', '', 7);
47 
48  //Posición: a 1,5 cm del final
49  $this->SetY(-18);
50  //Arial italic 8
51  $this->SetFont('Arial','',7);
52  //Número de página
53  $this->Cell(0,10, $config->$active_app->name,0,0,'C');
54 
55  //Posición: a 1,5 cm del final
56  $this->SetY(-10);
57  //Arial italic 8
58  $this->SetFont('Arial','',8);
59  //Número de página
60  $this->Cell(0,10,'-- '.$this->PageNo().' --',0,0,'C');
61 
62  }
63 
64 }
65 
75 function pdf($result, $sumArray, $title, $weightArray, $headerArray){
76 
77  $config = Config::read('config');
78  $active_app = Router::get_application();
79 
80  //Orientación if($sumArray>200) { $orientation = 'L'; } else { $orientation = 'P'; } $numRows = 140; //Tipo de Papel if($sumArray>250) { $paper = 'legal'; } else { $paper = 'letter'; } if($paper=='letter'&&$orientation=='P'){ $widthPage = 220; $numRows = 42; } if($paper=='legal'&&$orientation=='L'){ $widthPage = 355; $numRows = 30; } if($paper=='letter'&&$orientation=='L'){ $widthPage = 270; $numRows = 30; } //Crear Documento PDF $pdf = new PDF($orientation, 'mm', $paper); $pdf->Open(); $pdf->AddPage(); //Nombre del Listado $pdf->SetFillColor(255, 255, 255); $pdf->AddFont('Verdana','','verdana.php'); $pdf->SetFont('Verdana','', 14); $pdf->SetY(20); $pdf->SetX(0); $pdf->Ln(); if($config->$active_app->name){ $pdf->MultiCell(0, 6, strtoupper($config->$active_app->name), 0, "C", 0); } $pdf->MultiCell(0, 6, "REPORTE DE ".strtoupper($title), 0, "C", 0); $pdf->SetFont('Verdana','', 12); if(isset($_SESSION['fecsis'])){ $pdf->MultiCell(0, 6, "FECHA ".date("Y-m-d"), 0, "C", 0); } $pdf->Ln(); //Colores, ancho de línea y fuente en negrita $pdf->SetFillColor(0xF2,0xF2, 0xF2); $pdf->SetTextColor(0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(.2); $pdf->SetFont('Arial', 'B', 10); if($weightArray[0]<11){ $weightArray[0] = 11; } //Parametros del Reporte $pos = floor(($widthPage/2)-($sumArray/2)); $pdf->SetX($pos); for($i=0;$i<=count($headerArray)-1;$i++){ $pdf->Cell($weightArray[$i],7,$headerArray[$i], 1, 0, 'C', 1); } $pdf->Ln(); //Restauración de colores y fuentes $pdf->SetFillColor(224, 235, 255); $pdf->SetTextColor(0); $pdf->SetFont('Arial','B', 7); //print_r($weightArray); //Buscamos y listamos $n = 1; $p = 1; $t = 0; foreach($result as $row){ //$pdf->Cell(Ancho, Alto, contenido, ?, ?, Align) if($n>$numRows||($p==1&&($n>$numRows-3))){ $pdf->AddPage($orientation); $pdf->SetY(30); $pdf->SetX($pos); $pdf->SetFillColor(0xF2,0xF2, 0xF2); $pdf->SetTextColor(0); $pdf->SetDrawColor(0,0,0); $pdf->SetLineWidth(.2); $pdf->SetFont('Arial', 'B', 10); for($i=0;$i<count($headerArray);$i++){ $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1); } $pdf->Ln(); $pdf->SetFillColor(224, 235, 255); $pdf->SetTextColor(0); $pdf->SetFont('Arial', 'B', 7); $n = 1; $p++; } $pdf->SetX($pos); for($i=0;$i<=count($row)-1;$i++){ if(is_numeric($row[$i])){ $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'C'); } else { $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'L'); } } $n++; $t++; $pdf->Ln(); } $pdf->SetX($pos); $pdf->SetFont('Arial', 'B', 7); $pdf->SetFillColor(0xF2,0xF2, 0xF2); $pdf->Cell($weightArray[0], 5, "TOTAL",'LRTB', 0, 'R'); $pdf->Cell($weightArray[1], 5, $t,'LRTB', 0, 'L'); /*print "<div style='background: url(img/bg2.jpg) #F2f2f2;border:1px solid #c0c0c0'> <table><td><img src='img/information.gif' width='64' height='64'/></td><td>"; print "Papel: $paper<br>"; print "Orientación: $orientation<br>"; print "Ancho Página: $widthPage mm<br>"; print "Número Páginas: $p<br>"; print "</td></table></div><br>";*/ $file = md5(uniqid()); $pdf->Output(CORE_PATH.'public/temp/'.$file .".pdf", 'F'); if(isset($raw_output)){ print "<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>"; } else { Generator::forms_print("<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>"); } } ?>
81  if($sumArray>200) {
82  $orientation = 'L';
83  } else {
84  $orientation = 'P';
85  }
86 
87  $numRows = 140;
88  //Tipo de Papel
89  if($sumArray>250) {
90  $paper = 'legal';
91  } else {
92  $paper = 'letter';
93  }
94 
95  if($paper=='letter'&&$orientation=='P'){
96  $widthPage = 220;
97  $numRows = 42;
98  }
99 
100  if($paper=='legal'&&$orientation=='L'){
101  $widthPage = 355;
102  $numRows = 30;
103  }
104 
105  if($paper=='letter'&&$orientation=='L'){
106  $widthPage = 270;
107  $numRows = 30;
108  }
109 
110  //Crear Documento PDF
111  $pdf = new PDF($orientation, 'mm', $paper);
112 
113  $pdf->Open();
114  $pdf->AddPage();
115 
116  //Nombre del Listado
117  $pdf->SetFillColor(255, 255, 255);
118  $pdf->AddFont('Verdana','','verdana.php');
119  $pdf->SetFont('Verdana','', 14);
120  $pdf->SetY(20);
121  $pdf->SetX(0);
122 
123 
124  $pdf->Ln();
125 
126  if($config->$active_app->name){
127  $pdf->MultiCell(0, 6, strtoupper($config->$active_app->name), 0, "C", 0);
128  }
129  $pdf->MultiCell(0, 6, "REPORTE DE ".strtoupper($title), 0, "C", 0);
130  $pdf->SetFont('Verdana','', 12);
131  if(isset($_SESSION['fecsis'])){
132  $pdf->MultiCell(0, 6, "FECHA ".date("Y-m-d"), 0, "C", 0);
133  }
134  $pdf->Ln();
135 
136  //Colores, ancho de línea y fuente en negrita
137  $pdf->SetFillColor(0xF2,0xF2, 0xF2);
138  $pdf->SetTextColor(0);
139  $pdf->SetDrawColor(0,0,0);
140  $pdf->SetLineWidth(.2);
141  $pdf->SetFont('Arial', 'B', 10);
142 
143  if($weightArray[0]<11){
144  $weightArray[0] = 11;
145  }
146 
147  //Parametros del Reporte
148  $pos = floor(($widthPage/2)-($sumArray/2));
149  $pdf->SetX($pos);
150  for($i=0;$i<=count($headerArray)-1;$i++){
151  $pdf->Cell($weightArray[$i],7,$headerArray[$i], 1, 0, 'C', 1);
152  }
153  $pdf->Ln();
154 
155  //Restauración de colores y fuentes
156  $pdf->SetFillColor(224, 235, 255);
157  $pdf->SetTextColor(0);
158  $pdf->SetFont('Arial','B', 7);
159 
160  //print_r($weightArray);
161 
162  //Buscamos y listamos
163  $n = 1;
164  $p = 1;
165  $t = 0;
166  foreach($result as $row){
167  //$pdf->Cell(Ancho, Alto, contenido, ?, ?, Align)
168  if($n>$numRows||($p==1&&($n>$numRows-3))){
169  $pdf->AddPage($orientation);
170  $pdf->SetY(30);
171  $pdf->SetX($pos);
172  $pdf->SetFillColor(0xF2,0xF2, 0xF2);
173  $pdf->SetTextColor(0);
174  $pdf->SetDrawColor(0,0,0);
175  $pdf->SetLineWidth(.2);
176  $pdf->SetFont('Arial', 'B', 10);
177  for($i=0;$i<count($headerArray);$i++){
178  $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1);
179  }
180  $pdf->Ln();
181  $pdf->SetFillColor(224, 235, 255);
182  $pdf->SetTextColor(0);
183  $pdf->SetFont('Arial', 'B', 7);
184  $n = 1;
185  $p++;
186  }
187  $pdf->SetX($pos);
188  for($i=0;$i<=count($row)-1;$i++){
189  if(is_numeric($row[$i])){
190  $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'C');
191  } else {
192  $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'L');
193  }
194  }
195  $n++;
196  $t++;
197  $pdf->Ln();
198 
199  }
200 
201  $pdf->SetX($pos);
202  $pdf->SetFont('Arial', 'B', 7);
203  $pdf->SetFillColor(0xF2,0xF2, 0xF2);
204  $pdf->Cell($weightArray[0], 5, "TOTAL",'LRTB', 0, 'R');
205  $pdf->Cell($weightArray[1], 5, $t,'LRTB', 0, 'L');
206 
207  /*print "<div style='background: url(img/bg2.jpg) #F2f2f2;border:1px solid #c0c0c0'>
208  <table><td><img src='img/information.gif' width='64' height='64'/></td><td>";
209  print "Papel: $paper<br>";
210  print "Orientación: $orientation<br>";
211  print "Ancho Página: $widthPage mm<br>";
212  print "Número Páginas: $p<br>";
213  print "</td></table></div><br>";*/
214 
215  $file = md5(uniqid());
216  $pdf->Output(CORE_PATH.'public/temp/'.$file .".pdf", 'F');
217  if(isset($raw_output)){
218  print "<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>";
219  } else {
220  Generator::forms_print("<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>");
221  }
222 
223 }
224 ?>