Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2011, 22:58
angelitodiaz
 
Fecha de Ingreso: mayo-2011
Ubicación: Venezuela
Mensajes: 18
Antigüedad: 13 años
Puntos: 0
Pregunta FPDF y Saltos de Pagina

Hola.

Estoy realizando una consulta de base de datos mysql en donde almaceno el resultado en un array que luego recorro iterativamente a traves de un bucle foreach para construir junto a la clase FPDF un reporte.
Tengo el siguiente problema: Cuando presento los datos, estos en forma consecutiva se presentan en celdas contiguas sin ninguna novedad en el ancho y alto especificado y lo hace haciendo un salto de linea al llegar al final del margen derecho. Hasta alli todo es correcto. Ahora pasa que tengo 17 registros en la BD y en la primera hoja se presentan ordenados los primeros 14 en 14 filas seguidas. Inmediatamente se hace el salto de pagina pues se alcanzo el margen inferior derecho y sucede que cada fila consta de 17 columnas y cuando comienza a imprimir la pagina 2 escribe cada columna con un salto de pagina osea hace 17 paginas una por cada columna y todo esto para el registro 14, luego sigue en forma ordenada presentando los 2 registros siguientes. Mi codigo es el siguiente:

Código PHP:


require('fpdf/fpdf.php');

//Vienen por la URL las variables x, y y z
    
class PDF extends FPDF 

var 
$col=0;  

    function 
Header() 
    { 
        
//Logo
        
$this->Image('imagenes/imagen.jpg'60 1015015 'JPG');
        
        
//$this->Ln(10);
        
        //Select Arial bold 15 
        
$this->SetFont('Times','B',10);  
        
        
$this->SetXY(10,28);
        
$this->Write(2,'Col1: ');
        
        
$this->SetXY(120,28);
        
$this->Write(2,$_GET['y']);
        
        
$this->SetXY(210,28);
        
$this->Write(2,'Col2 ');

        
$this->SetFont('Times','',10);

        
$this->SetXY(100,32);
        
$this->Write(2,'Col3');
        
        
$this->Line5,35,275,35);

        
//$this->Ln(5);
                
        
$this->SetFont('Times','',7);
        
        
$this->SetFillColor(192,192,192);
        
$this->SetXY(125,38);
        
$this->MultiCell(88,5,'Asignaciones',1,'C',1);
            
        
$this->SetFillColor(220,220,220);    
        
$this->SetXY(10,43);
        
$this->MultiCell(5,10,'N.',1,'C',1);

        
$this->SetXY(15,43);
        
$this->MultiCell(25,10,'Nombre ',1,'C',1);

        
$this->SetXY(40,43);
        
$this->MultiCell(15,10,'Cedula',1,'C',1);

        
$this->SetXY(55,43);
        
$this->MultiCell(20,10,'Cargo',1,'C',1);

        
$this->SetXY(75,43);
        
$this->MultiCell(20,10,'Sueldo',1,'C',1);

        
$this->SetXY(95,43);
        
$this->MultiCell(15,10,'P',1,'C',1);

        
$this->SetXY(110,43);
        
$this->MultiCell(15,5,'N',1,'C',1);

        
$this->SetXY(125,43);
        
$this->MultiCell(15,5,'P',1,'C',1);    

        
$this->SetXY(140,43);
        
$this->MultiCell(13,5,'P',1,'C',1);

        
$this->SetXY(153,43);
        
$this->MultiCell(12,5,'S',1,'C',1);    
        
        
$this->SetXY(165,43);
        
$this->MultiCell(12,5,'S',1,'C',1);    

        
$this->SetXY(177,43);
        
$this->MultiCell(12,5,'P',1,'C',1);    
        
        
$this->SetXY(189,43);
        
$this->MultiCell(12,5,'B',1,'C',1);    

        
$this->SetXY(201,43);
        
$this->MultiCell(12,5,'O',1,'C',1);    

        
$this->SetXY(213,43);
        
$this->MultiCell(17,5,'Total ',1,'C',1);    

        
$this->SetXY(230,43);
        
$this->MultiCell(17,5,'Total 1',1,'C',1);    

        
$this->SetFont('Times','B',7);

        
$this->SetXY(247,43);
        
$this->MultiCell(17,5,'Total 2',1,'C',1);    
    } 


    function 
tabla($data)
    {
        
        
$this->SetFillColor(220,220,220);
        
$w=array(5,25,15,20,20,15,15,15,13,12,12,12,12,12,17,17,17);   // en este arreglo definiremos el ancho de cada columna
        
foreach($data as $row)
        {
              
$columna explode(";",$row); //separar los datos en posiciones de arreglo
            
            
$y $this->GetY();
            
$this->MultiCell($w[0],10,$columna[0],1,'R',1); //celda(ancho,alto,salto de linea,border,alineacion,relleno)
            
$this->SetXY(15,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[1],10,$columna[1],1,'L',0);
            
$this->SetXY(40,$y);
            
$y $this->GetY();            
            
$this->MultiCell($w[2],10,$columna[2],1,'R',0);
            
$this->SetXY(55,$y);
            
$y $this->GetY();
              
$this->MultiCell($w[3],5,$columna[3],1,'R',0);
            
$this->SetXY(75,$y);
            
$y $this->GetY();    
            
$this->MultiCell($w[4],10,$columna[4],1,'R',0);
            
$this->SetXY(95,$y);
            
$y $this->GetY();    
            
$this->MultiCell($w[5],10,$columna[5],1,'R',0);
            
$this->SetXY(110,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[6],10,$columna[6],1,'R',0);
            
$this->SetXY(125,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[7],10,$columna[7],1,'R',0);
            
$this->SetXY(140,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[8],10,$columna[8],1,'R',0);
            
$this->SetXY(153,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[9],10,$columna[9],1,'R',0);
            
$this->SetXY(165,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[10],10,$columna[10],1,'R',0);
            
$this->SetXY(177,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[11],10,$columna[11],1,'R',0);
            
$this->SetXY(189,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[12],10,$columna[12],1,'R',0);
            
$this->SetXY(201,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[13],10,$columna[13],1,'R',0);
            
$this->SetXY(213,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[14],10,$columna[14],1,'R',0);
            
$this->SetXY(230,$y);
            
$y $this->GetY();
            
$this->MultiCell($w[15],10,$columna[15],1,'R',0);
            
$this->SetXY(247,$y);
            
$this->MultiCell($w[16],10,$columna[16],1,'R',0);    
        }        
}
}


//llenar variable dat con los campos de una fila unidos por ;
while ($i <= 17)
{         
$dat[$i]=$i.";".$i+1.";".$i+2.";".$i+3.";".$i+4.";".$i+5.";".$i+6.";".$i+7.";".$i+8.";".$i+9.";".$i+10.";".$i+11.";".$i+12.";".$i+13.";".$i+14.";".$i+15.";".$i+16//concatenar para luego ser separado por explode()
$i++;
}

    
//Se construye el documento
        
    
$pdf=new PDF('L','mm','letter');


    
//Primera página
    
$pdf->AddPage();

    
$pdf->tabla($dat); 

    
$pdf->Output(); 
Oigan estoy loco tengo trabado alli ya dos dias y he probado un monton de cosas. Tal vez alguno se halla enfrentado a lo mismo y lo soluciono efectivamente. Gracias por su ayuda.