Reportes PDF Con La Clase FPDF

March 26, 2023 | Author: Anonymous | Category: N/A
Share Embed Donate


Short Description

Download Reportes PDF Con La Clase FPDF...

Description

 

REPORTES PDF CON LA CLASE FPDF, PHP Y MYSQL ¿Qué es FPDF?

FPDF es una clase escrita en PHP que permite generar documentos PDF directamente desde PHP, es decir, sin usar la biblioteca PDFlib. La F de FPDF significa Free (gratis y libre): puede usted usarla para cualquier propósito y modificarla a su gusto para satisfacer  sus necesidad necesidades. es.

FPDF tiene otras ventajas: funciones de alto nivel. Esta es una lista de sus principales características:

* Elección de la unidad de medida, formato de página y márgenes * Gestión de cabeceras y pies de página * Salto de página automático * Salto de línea y justificación del texto automáticos * Admisión de imágenes (JPEG, PNG y GIF) * Colores * Enlaces * Admisión de fuentes TrueType, Type1 y codificación * Compresión de página

La clase se puede descargar descargar en la página oficial http://www.fpdf.org/

Una vez que la incluyas dentro de tu carpeta de proyectos web, puedes crear un pdf como lo desees.. Aquí mi ejemplo particular, ṕara adaptarlo puedes configurar tu clave usuario, y

base de datos a usar, modificas las consultas a conveniencia, en este caso hay dos tablas dos funciones y dos consultas..

SetFillColor(62,102,60); SetFillColor( 62,102,60); // fondo de celda $this->SetTextColor(255); $this->SetTextC olor(255); // color del texto $this->SetDrawColor(0,0, $this->SetDra wColor(0,0,0); 0); // color de linea $this->SetLineWidth(.3); $this->SetLin eWidth(.3); // ancho de linea $this->SetFont('Arial','', 7); $this->SetFont('Arial','', $w=array(20,100,15,10,1 $w=array(2 0,100,15,10,15,15,15); 5,15,15); // en este arreglo definiremos el ancho de cada

 

columna for($i=0;$iCell($w[$i],4,$he for($i=0;$iCe ll($w[$i],4,$header[$i],1,0,'C',1) ader[$i],1,0,'C',1);; //por cada encabeza encabezado do existente, crea una celda $this->Ln(); //Colores, ancho de línea y fuente en negrita de CONTENIDO $this->SetFillColor(244,244,244); $this->SetFillColor(244,2 44,244); // $this->SetTextColor(0); $this->SetFont(''); //Datos $fill=false; // variable para alternar relleno foreach($data foreach($dat a as $row) { $columna = explode(";",$row); explode(";",$row); //separar los datos en posiciones de arreglo $this->Cell($w[0],6,$column $this->Cell($w [0],6,$columna[0],'LR',0,'L',$fill); a[0],'LR',0,'L',$fill); //celda(ancho //celda(ancho,alto,salto ,alto,salto de linea,border,alineacion,relleno) $this->Cell($w[1],6,$columna[1],'LR',0,'L',$fill); $this->Cell($w[1],6,$column a[1],'LR',0,'L',$fill); $this->Cell($w[2],6,$column $this->Cell($w [2],6,$columna[2],'LR',0,'L',$fill); a[2],'LR',0,'L',$fill); $this->Cell($w[3],6,$column $this->Cell($w [3],6,$columna[3],'LR',0,'L',$fill); a[3],'LR',0,'L',$fill); $this->Cell($w[4],6,$column $this->Cell($w [4],6,$columna[4],'LR',0,'L',$fill); a[4],'LR',0,'L',$fill); $this->Cell($w[5],6,$column $this->Cell($w [5],6,$columna[5],'LR',0,'L',$fill); a[5],'LR',0,'L',$fill); $this->Cell($w[6],6,$column $this->Cell($w [6],6,$columna[6],'LR',0,'L',$fill); a[6],'LR',0,'L',$fill); $this->Ln(); $fill=!$fill; //se alterna el valor del boolean $fill para cambiar relleno } $this->Cell(array_sum($w),0,'','T'); } function tabla1($header1,$data1) { //Colores, ancho de línea y fuente en negrita de CABECERA CABECERA $this->SetFillColor(62,1 $this->SetFill Color(62,102,60); 02,60); // fondo de celda $this->SetTextColor(255); $this->SetTextC olor(255); // color del texto $this->SetDrawColor(0,0, $this->SetDra wColor(0,0,0); 0); // color de linea $this->SetLineWidth(.3); $this->SetLin eWidth(.3); // ancho de linea $this->SetFont('Arial','', $this->SetFon t('Arial','', 6); // negrita $w=array(70); // en este arreglo definiremos el ancho de cada columna for($i=0;$iCell($w[$i],4,$he for($i=0;$iCe ll($w[$i],4,$header1[$i],1,0,' ader1[$i],1,0,'C',1); C',1); //por cada encabezado existente, crea una

 

celda $this->Ln(); //Colores, ancho de línea y fuente en negrita de CONTENIDO $this->SetFillColor(244,2 $this->SetFill Color(244,244,244); 44,244); // $this->SetTextColor(0); $this->SetFont(''); //Datos $fill=false; // variable para alternar relleno foreach($data1 as $row) { $columna = explode(";",$row); explode(";",$row); //separar los datos en posiciones de arreglo

// validación a mano para que respete el limite de la celda

if ($columna ($columna[0]>$w[0]){ [0]>$w[0]){ $this->Cell($w[0],20,$columna[0],'LR',1,'L',$fill) $this->Cell($w[0],20,$colu mna[0],'LR',1,'L',$fill);; //celda(anch //celda(ancho,alto,salto o,alto,salto de linea,border,alineacion,relleno) } else{ $this->Cell($w[0],5,substr($co $this->Cell($w [0],5,substr($columna[0],0, lumna[0],0, 45),'LR',1,'L',$fill); $this->Cell($w[0],5,substr($co $this->Cell($w [0],5,substr($columna[0],45,5 lumna[0],45,53),'LR',1,'L',$fill); 3),'LR',1,'L',$fill); $this->Cell($w[0],5,substr($co $this->Cell($w [0],5,substr($columna[0],99,1 lumna[0],99,150),'LR',1,'L',$fill); 50),'LR',1,'L',$fill); $this->Ln(0); } $fill=!$fill; //se alterna el valor del boolean $fill para cambiar relleno } $this->Cell(array_sum($w),0,'','T'); } function Footer() { //Pie de página $this->SetY(-15); $this->SetFont('Arial','I',10); $this->SetTextColor(128); $this->Cell(0,10,'Pagina $this->Cell(0,1 0,'Pagina '.$this->PageNo().' '.$this->PageNo().' de {nb}',0,0,'C'); // el parametro {nb} es generado por una funcion llamada AliasNbPages

 

} } $pdf = new PDF(); $pdf->AliasNbPages(); $pdf->Alias NbPages(); //funcion que calcula el numero de paginas $sql1 = "SELECT informacion FROM empresa"; $modificar11 = mysql_quer mysql_query($sql1, y($sql1, $conex) or die(mysql_error()); $head1 = array("VENEZOLANA DE RIEGO, C.A"); // cabecera $i=0; while ($fila=mysql_fetch_array($mod ($fila=mysql_fetch_array($modificar11)){ ificar11)){ //llenar variable dat con los campos de una fila unidos por ; $dat1[$i]=$fila[0]; $dat1[$i]=$fila [0]; //concatenar para luego ser separado por explode() $i++; } $sql = "SELE "SELECT CT codigo, descripcion, unidad, cantidad, precio_uni, descuento, total FROM orden_articulos orden_artic ulos where orden='10 orden='10733'"; 733'"; $modificar1 = mysql_query($sql, $conex) or die(mysql_error()); $head = array("Codigo","Descripcion","Unidad","Cant","Precio","Dcto","Total"); // cabecera $i=0; while ($fila=mysql_fetch_array($mod ($fila=mysql_fetch_array($modificar1)){ ificar1)){ //llenar variable dat con los campos de una fila unidos por ; $dat[$i]=$fila[0].";".($fila[1])." $dat[$i]=$fila[0]." ;".($fila[1]).";".$fila[2].";".$fila[3 ;".$fila[2].";".$fila[3].";".$fila[4].";" ].";".$fila[4].";".$fila[5].";".$fila[ .$fila[5].";".$fila[6]; 6]; //concatenar  para luego ser separado por explode() $i++; } $pdf->AddPage(); $pdf->AddP age(); //crear documento $pdf->Image('images/logo $pdf->Image(' images/logo.jpg',10,8,30,30); .jpg',10,8,30,30); //añadir imagen $pdf->Cell(50); $pdf->SetFont('Arial','',12); $pdf->Cell(120,15,"ORDEN DE COMPRA",0,0,'C'); $pdf->Ln(35); $pdf->SetFont('Arial','',12); $pdf->Ln(10); $pdf->tabla1($head1,$dat1); $pdf->Ln(30); $pdf->tabla($head,$dat);

 

$pdf->Output(); ); //el resto es historia $pdf->Output( ?>

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF