Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/10/2012, 09:10
sheshito
 
Fecha de Ingreso: septiembre-2008
Mensajes: 257
Antigüedad: 15 años, 7 meses
Puntos: 4
Al generar un pdf se me bloquea el navegador

Saludos, en mi web tengo que generar un pdf con cierta informacion de la bd...si me genera bien ....el problema es que cuando mando a generar el pdf se me bloquea el navegador, es decir cuando comienza a trabajar haciendo las consultas y generar el pdf el puntero del mouse se pone con el circulo de espera y tambien todo el navegador queda bloqueado no me permite cambiar a otra pagina ni nada.

Para generar el pdf estoy utilizando fpdf, lo que me gustaria es hacer de alguna forma que el pdf se genere y ya cuando este listo ahi muestre al usuario...alguien sabe como hacer esto, o quiza en mi codigo hay algo raro, les pongo el codigo q estoy utilizando, cabe mencionar q no es mi proipio codigo es algo q encontre en la red y le hize algunos cambios para acomodar a mis necesidades:
Código PHP:
require('fpdf/fpdf.php');
require(
'conexion1.php');
class 
PDF extends FPDF
{
var 
$widths;
var 
$aligns;

function 
SetWidths($w)
{
    
//Set the array of column widths
    
$this->widths=$w;
}

function 
SetAligns($a)
{
    
//Set the array of column alignments
    
$this->aligns=$a;
}

function 
Row($data)
{
    
//Calculate the height of the row
    
$nb=0;
    for(
$i=0;$i<count($data);$i++)
        
$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
    
$h=5*$nb;
    
//Issue a page break first if needed
    
$this->CheckPageBreak($h);
    
//Draw the cells of the row
    
for($i=0;$i<count($data);$i++)
    {
        
$w=$this->widths[$i];
        
$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
        
//Save the current position
        
$x=$this->GetX();
        
$y=$this->GetY();
        
//Draw the border

        
$this->Rect($x,$y,$w,$h);

        
$this->MultiCell($w,5,$data[$i],0,$a,'true');
        
//Put the position to the right of the cell
        
$this->SetXY($x+$w,$y);
    }
    
//Go to the next line
    
$this->Ln($h);
}

function 
CheckPageBreak($h)
{
    
//If the height h would cause an overflow, add a new page immediately
    
if($this->GetY()+$h>$this->PageBreakTrigger)
        
$this->AddPage($this->CurOrientation);
}

function 
NbLines($w,$txt)
{
    
//Computes the number of lines a MultiCell of width w will take
    
$cw=&$this->CurrentFont['cw'];
    if(
$w==0)
        
$w=$this->w-$this->rMargin-$this->x;
    
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    
$s=str_replace("\r",'',$txt);
    
$nb=strlen($s);
    if(
$nb>and $s[$nb-1]=="\n")
        
$nb--;
    
$sep=-1;
    
$i=0;
    
$j=0;
    
$l=0;
    
$nl=1;
    while(
$i<$nb)
    {
        
$c=$s[$i];
        if(
$c=="\n")
        {
            
$i++;
            
$sep=-1;
            
$j=$i;
            
$l=0;
            
$nl++;
            continue;
        }
        if(
$c==' ')
            
$sep=$i;
        
$l+=$cw[$c];
        if(
$l>$wmax)
        {
            if(
$sep==-1)
            {
                if(
$i==$j)
                    
$i++;
            }
            else
                
$i=$sep+1;
            
$sep=-1;
            
$j=$i;
            
$l=0;
            
$nl++;
        }
        else
            
$i++;
    }
    return 
$nl;
}

function 
Header()
{
$this->Image('recuperado56.jpeg',10,8,33);
    
$this->SetFont('Arial','',10);
    
$this->Text(20,14,'Historial clinico',0,'C'0);
    
$this->Ln(30);
}

function 
Footer()
{
    
$this->SetY(-15);
    
$this->SetFont('Arial','B',8);
    
$this->Cell(100,10,'Historial medico',0,0,'L');

}

}
$paciente$id;//lo tomo con otra consulta
    
$con = new DB;
    
$pacientes $con->conectar();

    
$strConsulta "SELECT nombre,apellido,sexo from paciente where id_paciente =  '$paciente'";

    
$pacientes mysql_query($strConsulta);

    
$fila mysql_fetch_array($pacientes);

    
$pdf=new PDF('L','mm','Letter');
    
$pdf->Open();
    
$pdf->AddPage();
    
$pdf->SetMargins(20,20,20);
    
$pdf->Ln(10);

    
$pdf->SetFont('Arial','',12);
    
$pdf->Cell(0,6,'Clave: '.$fila['clave'],0,1);
    
$pdf->Cell(10,10,'Nombre: '.$fila['nombre'],0,1);
    
$pdf->Cell(10,6,'Apellido: '.$fila['apellido'],0,1);
    
$pdf->Cell(10,6,'Sexo: '.$fila['sexo'],0,1);
        
$pdf->Cell(60,10,'mundo',0,1);

    
$pdf->Ln(10);

    
$pdf->SetWidths(array(1560555020));
    
$pdf->SetFont('Arial','B',10);
    
$pdf->SetFillColor(85,107,47);
    
$pdf->SetTextColor(255);

        for(
$i=0;$i<1;$i++)
            {
                
$pdf->Row(array('# Con','CONSULTA''FECHA','DIAGNOSTICO'));
            }

    
$historial $con->conectar();
    
$strConsulta "SELECT numero_consulta,motivo_consulta,fecha_consulta,diagnostico from consulta WHERE ci_paciente = '$paciente'";

    
$historial mysql_query($strConsulta);
    
$numfilas mysql_num_rows($historial);

    for (
$i=0$i<$numfilas$i++)
        {
            
$fila mysql_fetch_array($historial);
            
$pdf->SetFont('Arial','',10);

            if(
$i%== 1)
            {
                
$pdf->SetFillColor(153,255,153);
                
$pdf->SetTextColor(0);
                
$pdf->Row(array($fila['numero_consulta'],$fila['motivo_consulta'], $fila['fecha_consulta'], $fila['diagnostico']));
            }
            else
            {
                
$pdf->SetFillColor(102,204,51);
                
$pdf->SetTextColor(0);
                
$pdf->Row(array($fila['numero_consulta'],$fila['motivo_consulta'], $fila['fecha_consulta'], $fila['diagnostico']));
            }
        }

$pdf->Output();