Foros del Web » Programando para Internet » PHP » Frameworks y PHP orientado a objetos »

Ayuda con fpdf

Estas en el tema de Ayuda con fpdf en el foro de Frameworks y PHP orientado a objetos en Foros del Web. tengo el siguiente codigo Código PHP: define ( 'FPDF_FONTPATH' , 'font/' ); include( "fpdf.php" ); include( "comunes.php" ); include( "../clases/Cargar_clases.php" ); $libros =new  Libro (); ...
  #1 (permalink)  
Antiguo 09/06/2010, 12:54
 
Fecha de Ingreso: febrero-2009
Ubicación: mexico
Mensajes: 148
Antigüedad: 15 años, 2 meses
Puntos: 1
Ayuda con fpdf

tengo el siguiente codigo

Código PHP:
define('FPDF_FONTPATH','font/');
include(
"fpdf.php");
include(
"comunes.php");
include(
"../clases/Cargar_clases.php");

$libros=new Libro();
$rs=$libros->consultar("WHERE libros.id_autor=autores.id_autor AND libros.id_libros_seccion=libros_seccion.id_libros_seccion AND libros.id_editorial=editoriales.id_editorial ORDER BY libros.id_libro");

$rse2=$libros->suma_libros("ORDER BY id_libro");
$row2=$rse2->fetch_assoc();
$total_libros=$row2["total"];

$pdf=new PDF('L','mm',array(210,370));
$pdf->Open();
$pdf->AddPage();
$pdf->SetMargins(2.5,100);
$pdf->SetFont('Arial','B',16);
$pdf->SetFillColor(220220220);
$pdf->Text(140,20,"LISTA GENERAL DE LIBROS");
$pdf->SetFont('Arial','',8);
$pdf->MultiCell(0,5,"",0,'',L);
$pdf->Ln(20);
$header=array('CLAVE','TITULO','AUTOR','EDITORIAL','SECCION','AÑO EDICION','FECHA ALTA','ORIGINAL','COPIA','TOTAL');
$pdf->SetLineWidth(.2);
$pdf->SetFont('Arial','B',8);
$w=array(23,95,60,45,45,20,20,15,15,12);    
for(
$i=0;$i<count($header);$i++){
    
$pdf->Cell($w[$i],5,$header[$i],1,0,'C',1);
}
$pdf->Ln();
while(
$row=$rs->fetch_assoc()){
    
$clave=$row["id_libro"];
    
$nombre=$row["nombre"];
    
$autor=$row["nombre_autor"]." ".$row["apellidos"];
    
$editorial=$row["editorial"];
    
$seccion=$row["seccion"];
    
$ano_edicion=$row["ano_edicion"];
    
$fecha_alta=$row["fecha_alta"];
    
$original=$row["original"];
    
$copia=$row["copia"];
    
$rst=$libros->suma_libros("WHERE id_libro='$clave'");
    
$row1=$rst->fetch_assoc();
    
$suma=$row1["total"];
$pdf->Cell($w[0],5,$clave,1,'LR','C');
$pdf->Cell($w[1],5,$nombre,1,'LR','C');//Aqui esta el problema
$pdf->Cell($w[2],5,$autor,1,'LR','C');
$pdf->Cell($w[3],5,$editorial,1,'LR','C');
$pdf->Cell($w[4],5,$seccion,1,'LR','C');
$pdf->Cell($w[5],5,$ano_edicion,1,'LR','C');
$pdf->Cell($w[6],5,$fecha_alta,1,'LR','C');
$pdf->Cell($w[7],5,$original,1,'LR','C');
$pdf->Cell($w[8],5,$copia,1,'LR','C');
$pdf->Cell($w[9],5,$suma,1,'LR','C');
$pdf->Ln();
}
$pdf->Cell(338,5,"TOTAL DE LIBROS",1,0,"R");
$pdf->Cell(12,5,$total_libros,1,0,"C",0);
$pdf->Output("Lista_General_De_Libros_Biblioteca.pdf","D");
?> 
Me trae los datos de la base de datos correctamente, pero el problema esta esta linea que es donde se imprime el nombre del libro
$pdf->Cell($w[1],5,$nombre,1,'LR','C');

me imprime todos los nombre de libros, pero el datalle es que si el nombre del libro es muy largo me encima todo y se pasa a la otra celda que es la del autor, ya probe haciendo esto

$pdf->MultiCell($w[1],5,$nombre,1,'LR','C');

Pero me descompone el documento, alguien sabe como hacer para que el resultado de la consulta se ajuste al ancho de la celda o si sobrepasa el ancho de la celda de un salto o haga mas grande la celda, ayuda por favor
  #2 (permalink)  
Antiguo 11/06/2010, 07:00
 
Fecha de Ingreso: febrero-2009
Ubicación: mexico
Mensajes: 148
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Ayuda con fpdf

Bueno diran que tonto soy, pero ya resolvi yo solo el problema con este escript, por si a alguien le sirve

comunes.php
Código PHP:
<?
class PDF extends FPDF
{
//Cabecera de pgina
function Header()
{

    
//Logo
    
$this->Image('../imagenes/logo.png',320,5,30);
}

//Pie de pgina
function Footer()
{
  
$fecha=date("d-m-Y");
    
$this->SetFont('Arial','',6);
    
$this->SetY(-17);
    
$this->Cell(0,10,'Escuela Miguel Hidalgo',0,0,'C');
    
$this->SetY(-14);
    
$this->Cell(0,10,html_entity_decode('Cerrada de Juárez N° 327. Colonia Centro, Macuspana, Tabasco, México.'.$fecha),0,0,'C');
    
$this->SetY(-11);
    
$this->Cell(0,10,html_entity_decode('(936) 362-04-65'),0,0,'C');
    
$this->SetY(-8);
    
$this->Cell(0,10,'Pagina '.$this->PageNo().'',0,0,'C');    
}
/** Aqui **/
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] : 'J';
        
//Save the current position
        
$x=$this->GetX();
        
$y=$this->GetY();
        
//Draw the border
        
$this->Rect($x,$y,$w,$h);
        
//Print the text
        
$this->MultiCell($w,5,$data[$i],0,$a);
        
//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;
}
}
?>
ejemplo.php
Código PHP:
<?php
define
('FPDF_FONTPATH','font/');
include(
"fpdf.php");
include(
"comunes.php");
include(
"../clases/Cargar_clases.php");

$libros=new Libro();
$rs=$libros->consultar("WHERE libros.id_autor=autores.id_autor AND libros.id_libros_seccion=libros_seccion.id_libros_seccion AND libros.id_editorial=editoriales.id_editorial ORDER BY libros.id_libro");

$rse2=$libros->suma_libros("ORDER BY id_libro");
$row2=$rse2->fetch_assoc();
$total_libros=$row2["total"];


$pdf=new PDF('L','mm','Legal');
$pdf->AddPage();
$pdf->SetMargins(2.5,40);
$pdf->SetFont('Arial','B',16);
$pdf->SetFillColor(220220220);
$pdf->Text(140,20,"LISTA GENERAL DE LIBROS");
$pdf->SetFont('Arial','',8);
$pdf->Ln(30);
$pdf->SetLineWidth(.2);
$pdf->SetFont('Arial','B',8);
$pdf->cell(23,5,'CLAVE',1,0,C);    
$pdf->cell(95,5,'TITULO',1,0,C);
$pdf->cell(60,5,'AUTOR',1,0,C);
$pdf->cell(45,5,'EDITORIAL',1,0,C);
$pdf->cell(45,5,'SECCIÓN',1,0,C);
$pdf->cell(20,5,'EDICIÓN',1,0,C);
$pdf->cell(20,5,'ALTA',1,0,C);
$pdf->cell(15,5,'ORIGINAL',1,0,C);
$pdf->cell(15,5,'COPIA',1,0,C);
$pdf->cell(12,5,'TOTAL',1,0,C);
$pdf->Ln();
$pdf->SetWidths(array(23,95,60,45,45,20,20,15,15,12));
while(
$row1=$rs->fetch_assoc()){
    
$clave=$row1["id_libro"];
    
$nombre=$row1["nombre"];
    
$autor=$row1["nombre_autor"]." ".$row1["apellidos"];
    
$editorial=$row1["editorial"];
    
$seccion=$row1["seccion"];
    
$ano_edicion=$row1["ano_edicion"];
    
$fecha_alta=$row1["fecha_alta"];
    
$original=$row1["original"];
    
$copia=$row1["copia"];
    
$rst=$libros->suma_libros("WHERE id_libro='$clave'");
    
$row2=$rst->fetch_assoc();
    
$suma=$row2["total"];
    
$pdf->Row(array($clave,$nombre,$autor,$editorial,$seccion,$ano_edicion,$fecha_alta,$original,$copia,$suma));
}
$pdf->Cell(338,5,"TOTAL DE LIBROS",1,0,"R");
$pdf->Cell(12,5,$total_libros,1,0,"C",0);
$pdf->Output("Lista_General_De_Libros_Biblioteca.pdf","D");
?>

Etiquetas: fpdf
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:32.