Foros del Web » Programando para Internet » PHP »

Ayuda, novato con FPDF

Estas en el tema de Ayuda, novato con FPDF en el foro de PHP en Foros del Web. Aloha a toda la comunidad de foros del web!!! Grettings from mi pais!!! hahaha! xD soy novato con la libreria FPDF ( en realidad estoy ...
  #1 (permalink)  
Antiguo 26/06/2008, 14:33
Avatar de kovers  
Fecha de Ingreso: junio-2008
Ubicación: Caracas
Mensajes: 37
Antigüedad: 15 años, 10 meses
Puntos: 0
Ayuda, novato con FPDF

Aloha a toda la comunidad de foros del web!!! Grettings from mi pais!!! hahaha! xD soy novato con la libreria FPDF ( en realidad estoy aprendiendo por tutos que me he bajado ), lo que necesito es agregarle a un sistema de inventario que estoy realizando, la generacion de cualkier tipo de reporte en PDF... hasta los momentos he logrado halarme los datos dsd la mysql, he imprimirlos en el documento PDF, pero kisiera que en ese documento aparezca el banner del sistema, mas las tablas con los datos que estoy pidiendo en una consulta hacia la BD. Alli le dejo los codigos que estoy utilizando, que aun no se como enzamblarlos! espero me ayuden, graxias!!! bye bye

Código PHP:
<?php

define
('FPDF_FONTPATH','font/');

require(
'mysql_table.php');



class 
PDF extends PDF_MySQL_Table

{

function 
Header()

{

    
//Title

    
$this->SetFont('Arial','',18);

    
$this->Cell(0,6,'Reporte',0,1,'C');

    
$this->Ln(10);

    
//Ensure table header is output

    
parent::Header();

}

}



//Connect to database

mysql_connect('localhost','root','185264');

mysql_select_db('sabse');



$pdf=new PDF();

$pdf->Open();

$pdf->AddPage();

//First table: put all columns automatically

$pdf->Table('select nombre, apellido, ci, telefono from usuario');

$pdf->AddPage();

//Second table: specify 3 columns

$pdf->AddCol('rank',20,'','C');

$pdf->AddCol('name',40,'Country');

$pdf->AddCol('pop',40,'Pop (2001)','R');

$prop=array('HeaderColor'=>array(255,150,100),

            
'color1'=>array(210,245,255),

            
'color2'=>array(255,255,210),

            
'padding'=>2);

$pdf->Table('select nombre, apellido, ci, telefono from usuario',$prop);

$pdf->Output();

?>

<?php

require('fpdf.php');



class 
PDF_MySQL_Table extends FPDF

{

var 
$ProcessingTable=false;

var 
$aCols=array();

var 
$TableX;

var 
$HeaderColor;

var 
$RowColors;

var 
$ColorIndex;



function 
Header()

{

    
//Print the table header if necessary

    
if($this->ProcessingTable)

        
$this->TableHeader();

}



function 
TableHeader()

{

    
$this->SetFont('Arial','B',12);

    
$this->SetX($this->TableX);

    
$fill=!empty($this->HeaderColor);

    if(
$fill)

    
$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);

    foreach(
$this->aCols as $col)

        
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);

    
$this->Ln();

}



function 
Row($data)

{

    
$this->SetX($this->TableX);

    
$ci=$this->ColorIndex;

    
$fill=!empty($this->RowColors[$ci]);

    if(
$fill)

$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);

    foreach(
$this->aCols as $col)

        
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);

    
$this->Ln();

    
$this->ColorIndex=1-$ci;

}



function 
CalcWidths($width,$align)

{

    
//Compute the widths of the columns

    
$TableWidth=0;

    foreach(
$this->aCols as $i=>$col)

    {

        
$w=$col['w'];

        if(
$w==-1)

            
$w=$width/count($this->aCols);

        elseif(
substr($w,-1)=='%')

            
$w=$w/100*$width;

        
$this->aCols[$i]['w']=$w;

        
$TableWidth+=$w;

    }

    
//Compute the abscissa of the table

    
if($align=='C')

        
$this->TableX=max(($this->w-$TableWidth)/2,0);

    elseif(
$align=='R')

        
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);

    else

        
$this->TableX=$this->lMargin;

}



function 
AddCol($field=-1,$width=-1,$caption='',$align='L')

{

    
//Add a column to the table

    
if($field==-1)

        
$field=count($this->aCols);

    
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);

}



function 
Table($query,$prop=array())

{

    
//Issue query

    
$res=mysql_query($query) or die('Error: '.mysql_error()."<BR>Query: $query");

    
//Add all columns if none was specified

    
if(count($this->aCols)==0)

    {

        
$nb=mysql_num_fields($res);

        for(
$i=0;$i<$nb;$i++)

            
$this->AddCol();

    }

    
//Retrieve column names when not specified

    
foreach($this->aCols as $i=>$col)

    {

        if(
$col['c']=='')

        {

            if(
is_string($col['f']))

                
$this->aCols[$i]['c']=ucfirst($col['f']);

            else

                
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));

        }

    }

    
//Handle properties

    
if(!isset($prop['width']))

        
$prop['width']=0;

    if(
$prop['width']==0)

        
$prop['width']=$this->w-$this->lMargin-$this->rMargin;

    if(!isset(
$prop['align']))

        
$prop['align']='C';

    if(!isset(
$prop['padding']))

        
$prop['padding']=$this->cMargin;

    
$cMargin=$this->cMargin;

    
$this->cMargin=$prop['padding'];

    if(!isset(
$prop['HeaderColor']))

        
$prop['HeaderColor']=array();

    
$this->HeaderColor=$prop['HeaderColor'];

    if(!isset(
$prop['color1']))

        
$prop['color1']=array();

    if(!isset(
$prop['color2']))

        
$prop['color2']=array();

    
$this->RowColors=array($prop['color1'],$prop['color2']);

    
//Compute column widths

    
$this->CalcWidths($prop['width'],$prop['align']);

    
//Print header

    
$this->TableHeader();

    
//Print rows

    
$this->SetFont('Arial','',11);

    
$this->ColorIndex=0;

    
$this->ProcessingTable=true;

    while(
$row=mysql_fetch_array($res))

        
$this->Row($row);

    
$this->ProcessingTable=false;

    
$this->cMargin=$cMargin;

    
$this->aCols=array();

}

}

?>
chauuuuUUU!!! thanks!
  #2 (permalink)  
Antiguo 28/06/2008, 00:56
Avatar de WyLY  
Fecha de Ingreso: enero-2002
Ubicación: Cancun, México.
Mensajes: 506
Antigüedad: 22 años, 3 meses
Puntos: 6
De acuerdo Respuesta: Ayuda, novato con FPDF

Mira, yo hace poco maneje un poco de fpdf y en los plugins de la misma pagina de fpdf te viene como paginar al igual de como insertar una imagen ya queen mi caso la funcion de header() me creaba un error, en todo caso un ejemplo de mi archivo fue algo así:
Código PHP:
$pdf=new FPDF('L','mm','A4'); // ESTO ES PARA HORIZONTAL
$pdf->AddPage();// inicias
$pdf->Image('images/banner.jpg',10,8,270,'JPG');// insertar tu banner con las dimensiones pertinentes
$pdf->SetFont('Arial','B',14);// declaras texto
$pdf->SetY(30);//declaras Y
$pdf->Cell(0,6,'TU TEXTO',3,0,'C',1); // contenido
$pdf->Output();//salida. 
es para darte una idea, espero te ayude, un abrazo.
__________________
I do techy stuff for a living and practice MMA with my dog... He always wins.
  #3 (permalink)  
Antiguo 28/06/2008, 00:57
Avatar de WyLY  
Fecha de Ingreso: enero-2002
Ubicación: Cancun, México.
Mensajes: 506
Antigüedad: 22 años, 3 meses
Puntos: 6
Respuesta: Ayuda, novato con FPDF

Se me olvidó el include('fpdf.php') ;
__________________
I do techy stuff for a living and practice MMA with my dog... He always wins.
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 09:50.