Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/04/2013, 14:02
Avatar de jandrogdz
jandrogdz
 
Fecha de Ingreso: julio-2012
Ubicación: public $Guadalajara
Mensajes: 397
Antigüedad: 11 años, 10 meses
Puntos: 12
Pregunta Problema con tabla en fpdf

Buenas foro

Tengo un problema al tratar de crear una tabla con la librería FPDF.

Pero al tratar de hacer la tabla me arroja el ciclo pero en errores.
así esta el archivo para hacer la tabla:
Código PHP:
Ver original
  1. <?php
  2. require('fpdf.php');
  3.  
  4. class PDF_MC_Table extends FPDF
  5. {
  6. var $widths;
  7. var $aligns;
  8.  
  9. function SetWidths($w)
  10. {
  11.     //Set the array of column widths
  12.     $this->widths=$w;
  13. }
  14.  
  15. function SetAligns($a)
  16. {
  17.     //Set the array of column alignments
  18.     $this->aligns=$a;
  19. }
  20.  
  21. function Row($data)
  22. {
  23.     //Calculate the height of the row
  24.     $nb=0;
  25.     for($i=0;$i<count($data);$i++)
  26.         $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
  27.     $h=5*$nb;
  28.     //Issue a page break first if needed
  29.     $this->CheckPageBreak($h);
  30.     //Draw the cells of the row
  31.     for($i=0;$i<count($data);$i++)
  32.     {
  33.         $w=$this->widths[$i];
  34.         $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
  35.         //Save the current position
  36.         $x=$this->GetX();
  37.         $y=$this->GetY();
  38.         //Draw the border
  39.         $this->Rect($x,$y,$w,$h);
  40.         //Print the text
  41.         $this->MultiCell($w,5,$data[$i],0,$a);
  42.         //Put the position to the right of the cell
  43.         $this->SetXY($x+$w,$y);
  44.     }
  45.     //Go to the next line
  46.     $this->Ln($h);
  47. }
  48.  
  49. function CheckPageBreak($h)
  50. {
  51.     //If the height h would cause an overflow, add a new page immediately
  52.     if($this->GetY()+$h>$this->PageBreakTrigger)
  53.         $this->AddPage($this->CurOrientation);
  54. }
  55.  
  56. function NbLines($w,$txt)
  57. {
  58.     //Computes the number of lines a MultiCell of width w will take
  59.     $cw=&$this->CurrentFont['cw'];
  60.     if($w==0)
  61.         $w=$this->w-$this->rMargin-$this->x;
  62.     $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  63.     $s=str_replace("\r",'',$txt);
  64.     $nb=strlen($s);
  65.     if($nb>0 and $s[$nb-1]=="\n")
  66.         $nb--;
  67.     $sep=-1;
  68.     $i=0;
  69.     $j=0;
  70.     $l=0;
  71.     $nl=1;
  72.     while($i<$nb)
  73.     {
  74.         $c=$s[$i];
  75.         if($c=="\n")
  76.         {
  77.             $i++;
  78.             $sep=-1;
  79.             $j=$i;
  80.             $l=0;
  81.             $nl++;
  82.             continue;
  83.         }
  84.         if($c==' ')
  85.             $sep=$i;
  86.         $l+=$cw[$c];
  87.         if($l>$wmax)
  88.         {
  89.             if($sep==-1)
  90.             {
  91.                 if($i==$j)
  92.                     $i++;
  93.             }
  94.             else
  95.                 $i=$sep+1;
  96.             $sep=-1;
  97.             $j=$i;
  98.             $l=0;
  99.             $nl++;
  100.         }
  101.         else
  102.             $i++;
  103.     }
  104.     return $nl;
  105. }
  106. }
  107. ?>

Y este es el que hace el pdf:
Código PHP:
Ver original
  1. header ('Content-type: text/html; charset=utf-8');
  2. require('../../libs/fpdf/PDF_MC_Table.php'); // tiene el require de fpdf.
  3.  
  4. class PDF extends FPDF
  5. {
  6.     //Encabezado de pagina
  7.     function Header()
  8.     {  
  9.         $this->Image('../../imagenes/banner_pedidos.jpg',5,5,285,35,'JPG');
  10.         $this->Cell(200,35,"","",1,'C');
  11.     }
  12.    
  13.     function Footer()
  14.     {
  15.         $this->SetFont('Arial','B',10);
  16.         $this->SetY(-20);
  17.         $this->SetFont('Arial','I',12);
  18.         $this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,1,'C');
  19.     }
  20. }
  21.  
  22. $pdf=new PDF('L','mm','A4');
  23.     $pdf->AliasNbPages();
  24.     $pdf->AddPage();    
  25.     $pdf->Ln(5);
  26.  
  27. $pdf->Ln(5);
  28.     $pdf->SetFont('Arial','',12);
  29.     $pdf->SetTextColor(115,115,115);
  30.     $pdf->SetFillColor(237,237,237);
  31.     $pdf->SetDrawColor(215,215,215);
  32.     $pdf->SetLineWidth(.1);
  33.     $pdf->Cell(20,7,'Cantidad',"BRLT",0,'C',true);
  34.     $pdf->Cell(117,7,'  Producto | Servicio',"BRLT",0,'L',true);
  35.     $pdf->Cell(5,7,'P',"BRLT",0,'C',true);
  36.     $pdf->Cell(5,7,"D","BRLT",0,'C',true);
  37.     $pdf->Cell(5,7,"I","BRLT",0,'C',true);
  38.     $pdf->Cell(30,7,"$ Precio U.","BRLT",0,'C',true);
  39.     $pdf->Cell(30,7,"$ Importe","BRLT",0,'C',true);
  40.     $pdf->Cell(63,7,"Observaciones","BRLT",1,'C',true);
  41.     $pdf->Ln(1);
  42.    
  43.     $pdf->SetFont('Arial','',11);
  44.     $dgral = $ped->productosDetalle($_GET['dt']);
  45.     $contador = 0;
  46.    
  47.     $mc_table = new PDF_MC_Table();
  48.     $mc_table->SetWidths(array(20,117,5,5,5,30,30,63));
  49.     for($i=0;$i<1;$i++):
  50.         $mc_table->Row(array("Cantidad","Descripcion","P","D","I","Precio","Importe","Observaciones"));
  51.     endfor;

Esto me regresa:
Código texto:
Ver original
  1. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php on line 62
  2.  
  3. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php on line 62
  4.  
  5. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php on line 62
  6.  
  7. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php on line 62
  8.  
  9. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php on line 62
  10.  
  11. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  12.  
  13. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  14.  
  15. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  16.  
  17. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  18.  
  19. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  20.  
  21. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  22.  
  23. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  24.  
  25. Warning: Division by zero in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 700
  26.  
  27. Warning: Cannot modify header information - headers already sent by (output started at /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/PDF_MC_Table.php:62) in /home/iconogra/public_html/sistema/server_pruebas/libs/fpdf/fpdf.php on line 1017
  28. FPDF error: Some data has already been output, can't send PDF file

Alguien me puede apoyar.

Se los agradecería mucho la vdd
__________________
Lo imposible solo cuesta un poco mas